mcsallocator

package
v3.10.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFull            = errors.New("range is full")
	ErrNotInRange      = errors.New("provided label is not in the valid range")
	ErrAllocated       = errors.New("provided label is already allocated")
	ErrMismatchedRange = errors.New("the provided label does not match the current label range")
)

Functions

This section is empty.

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

func New

func New(r *mcs.Range, factory allocator.AllocatorFactory) *Allocator

New creates a Allocator over a UID range, calling factory to construct the backing store.

func NewInMemory

func NewInMemory(r *mcs.Range) *Allocator

NewInMemory creates an in-memory Allocator

func (*Allocator) Allocate

func (r *Allocator) Allocate(label *mcs.Label) error

Allocate attempts to reserve the provided label. ErrNotInRange or ErrAllocated will be returned if the label is not valid for this range or has already been reserved. ErrFull will be returned if there are no labels left.

func (*Allocator) AllocateNext

func (r *Allocator) AllocateNext() (*mcs.Label, error)

AllocateNext reserves one of the labels from the pool. ErrFull may be returned if there are no labels left.

func (*Allocator) Free

func (r *Allocator) Free() int

Free returns the count of port left in the range.

func (*Allocator) Has

func (r *Allocator) Has(label *mcs.Label) bool

Has returns true if the provided port is already allocated and a call to Allocate(label) would fail with ErrAllocated.

func (*Allocator) Release

func (r *Allocator) Release(label *mcs.Label) error

Release releases the port back to the pool. Releasing an unallocated port or a port out of the range is a no-op and returns no error.

func (*Allocator) Restore

func (r *Allocator) Restore(into *mcs.Range, data []byte) error

Restore restores the pool to the previously captured state. ErrMismatchedNetwork is returned if the provided port range doesn't exactly match the previous range.

func (*Allocator) Snapshot

func (r *Allocator) Snapshot(dst *api.RangeAllocation) error

Snapshot saves the current state of the pool.

type Interface

type Interface interface {
	Allocate(*mcs.Label) error
	AllocateNext() (*mcs.Label, error)
	Release(*mcs.Label) error
}

Interface manages the allocation of ports out of a range. Interface should be threadsafe.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL