pool

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckIdleInterval = 2 * time.Minute
)
View Source
const DefaultCapacity = 50
View Source
const DefaultMaxIdle = 20

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")
)

Functions

This section is empty.

Types

type Initializer

type Initializer func(holder ResourceHolder) error

type ObjectFactory

type ObjectFactory interface {
	Create() (types.NetworkResource, error)
	Dispose(types.NetworkResource) error
}

type ObjectPool

type ObjectPool interface {
	Acquire(ctx context.Context, resid string) (types.NetworkResource, error)
	ReleaseWithReverse(resId string, reverse time.Duration) error
	Release(resId string) error
	AcquireAny(ctx context.Context) (types.NetworkResource, error)
	Stat(resId string) error
}

func NewSimpleObjectPool

func NewSimpleObjectPool(cfg PoolConfig) (ObjectPool, error)

type PoolConfig

type PoolConfig struct {
	Factory     ObjectFactory
	Initializer Initializer
	MinIdle     int
	MaxIdle     int
	Capacity    int
}

type PriorityQeueu

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

func NewPriorityQueue

func NewPriorityQueue() *PriorityQeueu

func (*PriorityQeueu) Find

func (q *PriorityQeueu) Find(id string) *poolItem

func (*PriorityQeueu) Peek

func (q *PriorityQeueu) Peek() *poolItem

func (*PriorityQeueu) Pop

func (q *PriorityQeueu) Pop() *poolItem

func (*PriorityQeueu) Push

func (q *PriorityQeueu) Push(item *poolItem)

func (*PriorityQeueu) Rob

func (q *PriorityQeueu) Rob(id string) *poolItem

func (*PriorityQeueu) Size

func (q *PriorityQeueu) Size() int

type ResourceHolder

type ResourceHolder interface {
	AddIdle(resource types.NetworkResource)
	AddInuse(resource types.NetworkResource)
}

type SimpleObjectPool

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

func (*SimpleObjectPool) Acquire

func (p *SimpleObjectPool) Acquire(ctx context.Context, resId string) (types.NetworkResource, error)

func (*SimpleObjectPool) AcquireAny

func (*SimpleObjectPool) AddIdle

func (p *SimpleObjectPool) AddIdle(resource types.NetworkResource)

func (*SimpleObjectPool) AddInuse

func (p *SimpleObjectPool) AddInuse(res types.NetworkResource)

func (*SimpleObjectPool) Release

func (p *SimpleObjectPool) Release(resId string) error

func (*SimpleObjectPool) ReleaseWithReverse

func (p *SimpleObjectPool) ReleaseWithReverse(resId string, reverse time.Duration) error

func (*SimpleObjectPool) Stat

func (p *SimpleObjectPool) Stat(resId string) error

Jump to

Keyboard shortcuts

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