pool

package
v1.3.0-policy Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CheckIdleInterval the interval of check and process idle eni
	CheckIdleInterval = 2 * time.Minute
)

Variables

View Source
var (
	ErrNoAvailableResource = errors.New("no available resource")
	ErrInvalidState        = errors.New("invalid state")
	ErrNotFound            = errors.New("not found")
	ErrContextDone         = errors.New("context done")
	ErrInvalidArguments    = errors.New("invalid arguments")
)

Errors of pool

Functions

This section is empty.

Types

type Config added in v1.1.0

type Config struct {
	Name        string
	Type        string
	Factory     ObjectFactory
	Initializer Initializer
	MinIdle     int
	MaxIdle     int
	Capacity    int
}

Config configuration of pool

type Initializer

type Initializer func(holder ResourceHolder) error

Initializer of pool

type ObjectFactory

type ObjectFactory interface {
	// Create res with count
	Create(count int) ([]types.NetworkResource, error)
	Dispose(types.NetworkResource) error
	ListResource() (map[string]types.NetworkResource, error)
	Check(types.NetworkResource) error
	// Reconcile run periodicity
	Reconcile()
}

ObjectFactory interface of network resource object factory

type ObjectPool

type ObjectPool interface {
	Acquire(ctx context.Context, resID, idempotentKey string) (types.NetworkResource, error)
	ReleaseWithReservation(resID string, reservation time.Duration) error
	Release(resID string) error
	AcquireAny(ctx context.Context, idempotentKey string) (types.NetworkResource, error)
	Stat(resID string) (types.NetworkResource, error)
	GetName() string
	tracing.ResourceMappingHandler
}

ObjectPool object pool interface

func NewSimpleObjectPool

func NewSimpleObjectPool(cfg Config) (ObjectPool, error)

NewSimpleObjectPool return an object pool implement

type ResUsage added in v1.1.0

type ResUsage struct {
	ID     string
	Type   string
	Status types.ResStatus
}

ResUsage ResUsage

func (*ResUsage) GetID added in v1.1.0

func (r *ResUsage) GetID() string

func (*ResUsage) GetStatus added in v1.1.0

func (r *ResUsage) GetStatus() types.ResStatus

func (*ResUsage) GetType added in v1.1.0

func (r *ResUsage) GetType() string

type ResourceHolder

type ResourceHolder interface {
	AddIdle(resource types.NetworkResource)
	AddInvalid(resource types.NetworkResource)
	AddInuse(resource types.NetworkResource, idempotentKey string)
}

ResourceHolder interface to initialize pool

type Usage added in v1.1.0

type Usage struct {
	Local  map[string]types.Res
	Remote map[string]types.Res
}

Usage store res booth local and remote

func (*Usage) GetLocal added in v1.1.0

func (u *Usage) GetLocal() map[string]types.Res

func (*Usage) GetRemote added in v1.1.0

func (u *Usage) GetRemote() map[string]types.Res

Jump to

Keyboard shortcuts

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