Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type ObjectCreateFactory
- type ObjectDestroyFactory
- type ObjectValidateFactory
- type Pool
- func (p *Pool) ActiveSize() int
- func (p *Pool) BorrowObject(ctx context.Context) (interface{}, error)
- func (p *Pool) Close(ctx context.Context) error
- func (p *Pool) Evict(ctx context.Context) error
- func (p *Pool) IdleSize() int
- func (p *Pool) InvalidateObject(ctx context.Context, object interface{}) error
- func (p *Pool) ReturnObject(ctx context.Context, object interface{}) error
- func (p *Pool) Size() int
- func (p *Pool) StartEvictor()
Constants ¶
Variables ¶
View Source
var ( DefaultObjectValidateFactory ObjectValidateFactory = func(ctx context.Context, object interface{}) bool { return true } DefaultObjectDestroyFactory ObjectDestroyFactory = func(ctx context.Context, object interface{}) error { return nil } )
View Source
var ( ErrPoolClosed = errors.New("pool has been closed") ErrPoolFulled = errors.New("pool is full") ErrPoolExhausted = errors.New("pool is exhausted") ErrObjectNotFound = errors.New("object not found") ErrObjectValidateFailed = errors.New("object validate failed") ErrObjectCreateFactoryNotFound = errors.New("the factory of object creating not found") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
/**
The capacity of the pool. If MaxSize <= 0, no capacity limit.
*/
MaxSize int
/**
The minimum size of the idle objects.
*/
MinIdle int
/**
The maximal size of the idle objects. Idle objects exceeding MaxIdle will be evicted.
*/
MaxIdle int
/**
The minimum time that idle object should be reserved.
*/
MinIdleTime time.Duration
/**
The blocking policy. If true, it will return ErrPoolExhausted when pool is exhausted.
*/
Nonblocking bool
/**
Enable auto evict idle objects. When true, pool will create a goroutine to start a evictor.
*/
AutoEvict bool
/**
The interval between evict.
*/
EvictInterval time.Duration
/**
The maximal attempts to validate object.
*/
MaxValidateAttempts int
/**
The factory of creating object.
*/
ObjectCreateFactory ObjectCreateFactory
/**
The factory of validating object.
*/
ObjectValidateFactory ObjectValidateFactory
/**
The factory of destroying object.
*/
ObjectDestroyFactory ObjectDestroyFactory
}
func NewConfig ¶
func NewConfig(objectCreateFactory ObjectCreateFactory) Config
func NewDefaultConfig ¶
func NewDefaultConfig() Config
type ObjectCreateFactory ¶
type ObjectDestroyFactory ¶
type ObjectValidateFactory ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a thread-safe pool
func (*Pool) ActiveSize ¶
func (*Pool) BorrowObject ¶
BorrowObject promise to return a idle object. It will be blocked when there is no any idle object.
func (*Pool) InvalidateObject ¶
InvalidateObject delete and destroy the active object
func (*Pool) ReturnObject ¶
func (*Pool) StartEvictor ¶
func (p *Pool) StartEvictor()
Click to show internal directories.
Click to hide internal directories.