uidallocator

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2017 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 UID range is not in the valid range")
	ErrAllocated       = errors.New("provided UID range is already allocated")
	ErrMismatchedRange = errors.New("the provided UID range does not match the current UID range")
)

Functions

This section is empty.

Types

type Allocator

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

func New

func New(r *uid.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 *uid.Range) *Allocator

NewInMemory creates an in-memory Allocator

func (*Allocator) Allocate

func (r *Allocator) Allocate(block uid.Block) error

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

func (*Allocator) AllocateNext

func (r *Allocator) AllocateNext() (uid.Block, error)

AllocateNext reserves one of the ports from the pool. ErrFull may be returned if there are no ports 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(block uid.Block) bool

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

func (*Allocator) Release

func (r *Allocator) Release(block uid.Block) 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 *uid.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(uid.Block) error
	AllocateNext() (uid.Block, error)
	Release(uid.Block) 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