Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Name of pool Name string // Type of resource in pool Type string // TargetMin minimum number of all resources(contains the used) in pool TargetMin int // Target cache target of resource in pool Target int // MaxCap max capacity of pool MaxCap int // MaxCapProbe if enable the capacity detection function MaxCapProbe bool // MonitorInterval period of pool monitor MonitorInterval time.Duration // GCProtectPeriod protect period of resource while gc action GCProtectPeriod time.Duration // Factory to create resource in pool Factory ObjectFactory // PreStart run before the pool starts working PreStart ResourcePoolHook }
Config of pool.
type ObjectFactory ¶
type ObjectFactory interface { // Name of ObjectFactory Name() string // Create a certain amount of resources Create(count int) ([]types.NetResource, error) // Release destroy resource Release(resource types.NetResource) error // ReleaseInValid destroy invalid resource ReleaseInValid(resource types.NetResource) (types.NetResource, error) // Valid check if the resource is valid Valid(resource types.NetResource) error // List all resource created by ObjectFactory List() (map[types.ResStatus]map[string]types.NetResource, error) // GC sync objects in ObjectFactory with remote provider GC() error // GetResourceLimit get the maximum number of resources that can be created by ObjectFactory GetResourceLimit() int }
type ResourcePool ¶
type ResourcePool interface { // Name of ResourcePool Name() string // Allocate a specified or available types.NetResource from pool // If no resources are available in ResourcePool, create one Allocate(ctx context.Context, prefer, owner string) (types.NetResource, error) // Release a specified resource by ID Release(resID string) error // Status get Status of ResourcePool Status() Status // GetSnapshot get snapshot of ResourcePool GetSnapshot() (ResourcePoolSnapshot, error) // GC sync resource in ResourcePool with resource in ObjectFactory GC(getAllocatedResMap func() (map[string]types.NetResourceAllocated, error)) error // resourceId -- vpcResource // GetResourceLimit get the maximum number of resources that can be created by ObjectFactory GetResourceLimit() int // ReCfgCache reconfigure pooling parameters ReCfgCache(target, targetMin int) }
func NewResourcePool ¶
func NewResourcePool(config Config) (ResourcePool, error)
NewResourcePool create a ResourcePool according to Config.
type ResourcePoolHook ¶
type ResourcePoolHook func(pool ResourcePoolOp) error
type ResourcePoolOp ¶
type ResourcePoolOp interface { // AddInuse add a used resource to pool AddInuse(res types.NetResource, owner string) // AddInvalid add an invalid resource to pool AddInvalid(res types.NetResource) // AddAvailable add a available resource to pool AddAvailable(res types.NetResource) }
type ResourcePoolSnapshot ¶
type ResourcePoolSnapshot interface { // PoolSnapshot snapshot of pool PoolSnapshot() map[string]types.NetResourceStatus // MetaSnapshot snapshot of ObjectFactory MetaSnapshot() map[string]types.NetResourceStatus }
type ResourcePoolSnapshotCache ¶
type ResourcePoolSnapshotCache struct { Pool map[string]types.NetResourceStatus Meta map[string]types.NetResourceStatus }
func (*ResourcePoolSnapshotCache) MetaSnapshot ¶
func (r *ResourcePoolSnapshotCache) MetaSnapshot() map[string]types.NetResourceStatus
func (*ResourcePoolSnapshotCache) PoolSnapshot ¶
func (r *ResourcePoolSnapshotCache) PoolSnapshot() map[string]types.NetResourceStatus
Click to show internal directories.
Click to hide internal directories.