1 /* 2 Copyright 2014 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package allocator 18 19 // Interface manages the allocation of items out of a range. Interface 20 // should be threadsafe. 21 type Interface interface { 22 Allocate(int) (bool, error) 23 AllocateNext() (int, bool, error) 24 Release(int) error 25 ForEach(func(int)) 26 Has(int) bool 27 Free() int 28 29 // Destroy shuts down all internal structures. 30 // Destroy needs to be implemented in thread-safe way and be prepared for being 31 // called more than once. 32 Destroy() 33 } 34 35 // Snapshottable is an Interface that can be snapshotted and restored. Snapshottable 36 // should be threadsafe. 37 type Snapshottable interface { 38 Interface 39 Snapshot() (string, []byte) 40 Restore(string, []byte) error 41 } 42 43 type AllocatorFactory func(max int, rangeSpec string) (Interface, error) 44 45 type AllocatorWithOffsetFactory func(max int, rangeSpec string, offset int) (Interface, error) 46