Documentation ¶
Overview ¶
A generic resource pool for managing resources such as network connections.
Index ¶
- type ManagedHandle
- type ManagedHandleImpl
- func (c *ManagedHandleImpl) Discard() error
- func (c *ManagedHandleImpl) Handle() (interface{}, error)
- func (c *ManagedHandleImpl) Owner() ResourcePool
- func (c *ManagedHandleImpl) Release() error
- func (c *ManagedHandleImpl) ReleaseUnderlyingHandle() interface{}
- func (c *ManagedHandleImpl) ResourceLocation() string
- type MultiResourcePool
- func (p *MultiResourcePool) Discard(handle ManagedHandle) error
- func (p *MultiResourcePool) EnterLameDuckMode()
- func (p *MultiResourcePool) Get(resourceLocation string) (ManagedHandle, error)
- func (p *MultiResourcePool) ListRegistered() []string
- func (p *MultiResourcePool) NumActive() int32
- func (p *MultiResourcePool) NumIdle() int
- func (p *MultiResourcePool) Register(resourceLocation string) error
- func (p *MultiResourcePool) Release(handle ManagedHandle) error
- func (p *MultiResourcePool) Unregister(resourceLocation string) error
- type Options
- type ResourceLocationPool
- type ResourcePool
- type RoundRobinResourcePool
- func (p *RoundRobinResourcePool) Discard(handle ManagedHandle) error
- func (p *RoundRobinResourcePool) EnterLameDuckMode()
- func (p *RoundRobinResourcePool) Get(key string) (ManagedHandle, error)
- func (p *RoundRobinResourcePool) ListRegistered() []string
- func (p *RoundRobinResourcePool) NumActive() int32
- func (p *RoundRobinResourcePool) NumIdle() int
- func (p *RoundRobinResourcePool) Register(resourceLocation string) error
- func (p *RoundRobinResourcePool) Release(handle ManagedHandle) error
- func (p *RoundRobinResourcePool) Unregister(resourceLocation string) error
- type SimpleResourcePool
- func (p *SimpleResourcePool) Discard(handle ManagedHandle) error
- func (p *SimpleResourcePool) EnterLameDuckMode()
- func (p *SimpleResourcePool) Get(unused string) (ManagedHandle, error)
- func (p *SimpleResourcePool) ListRegistered() []string
- func (p *SimpleResourcePool) NumActive() int32
- func (p *SimpleResourcePool) NumIdle() int
- func (p *SimpleResourcePool) Register(resourceLocation string) error
- func (p *SimpleResourcePool) Release(handle ManagedHandle) error
- func (p *SimpleResourcePool) Unregister(resourceLocation string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ManagedHandle ¶
type ManagedHandle interface { // This returns the handle's resource location. ResourceLocation() string // This returns the underlying resource handle (or error if the handle // is no longer active). Handle() (interface{}, error) // This returns the resource pool which owns this handle. Owner() ResourcePool // The releases the underlying resource handle to the caller and marks the // managed handle as inactive. The caller is responsible for cleaning up // the released handle. This returns nil if the managed handle no longer // owns the resource. ReleaseUnderlyingHandle() interface{} // This indictes a user is done with the handle and releases the handle // back to the resource pool. Release() error // This indicates the handle is an invalid state, and that the // connection should be discarded from the connection pool. Discard() error }
A resource handle managed by a resource pool.
func NewManagedHandle ¶
func NewManagedHandle( resourceLocation string, handle interface{}, pool ResourcePool, options Options) ManagedHandle
This creates a managed handle wrapper.
type ManagedHandleImpl ¶
type ManagedHandleImpl struct {
// contains filtered or unexported fields
}
A physical implementation of ManagedHandle
func (*ManagedHandleImpl) Discard ¶
func (c *ManagedHandleImpl) Discard() error
See ManagedHandle for documentation.
func (*ManagedHandleImpl) Handle ¶
func (c *ManagedHandleImpl) Handle() (interface{}, error)
See ManagedHandle for documentation.
func (*ManagedHandleImpl) Owner ¶
func (c *ManagedHandleImpl) Owner() ResourcePool
See ManagedHandle for documentation.
func (*ManagedHandleImpl) Release ¶
func (c *ManagedHandleImpl) Release() error
See ManagedHandle for documentation.
func (*ManagedHandleImpl) ReleaseUnderlyingHandle ¶
func (c *ManagedHandleImpl) ReleaseUnderlyingHandle() interface{}
See ManagedHandle for documentation.
func (*ManagedHandleImpl) ResourceLocation ¶
func (c *ManagedHandleImpl) ResourceLocation() string
See ManagedHandle for documentation.
type MultiResourcePool ¶
type MultiResourcePool struct {
// contains filtered or unexported fields
}
A resource pool implementation that manages multiple resource location entries. The handles to each resource location entry acts independently. For example "tcp localhost:11211" could act as memcache shard 0 and "tcp localhost:11212" could act as memcache shard 1.
func (*MultiResourcePool) Discard ¶
func (p *MultiResourcePool) Discard(handle ManagedHandle) error
See ResourcePool for documentation.
func (*MultiResourcePool) EnterLameDuckMode ¶
func (p *MultiResourcePool) EnterLameDuckMode()
See ResourcePool for documentation.
func (*MultiResourcePool) Get ¶
func (p *MultiResourcePool) Get( resourceLocation string) (ManagedHandle, error)
See ResourcePool for documentation.
func (*MultiResourcePool) ListRegistered ¶
func (p *MultiResourcePool) ListRegistered() []string
func (*MultiResourcePool) NumActive ¶
func (p *MultiResourcePool) NumActive() int32
See ResourcePool for documentation.
func (*MultiResourcePool) NumIdle ¶
func (p *MultiResourcePool) NumIdle() int
See ResourcePool for documentation.
func (*MultiResourcePool) Register ¶
func (p *MultiResourcePool) Register(resourceLocation string) error
See ResourcePool for documentation.
func (*MultiResourcePool) Release ¶
func (p *MultiResourcePool) Release(handle ManagedHandle) error
See ResourcePool for documentation.
func (*MultiResourcePool) Unregister ¶
func (p *MultiResourcePool) Unregister(resourceLocation string) error
See ResourcePool for documentation.
type Options ¶
type Options struct { // The maximum number of active resource handles per resource location. (A // non-positive value indicates the number of active resource handles is // unbounded). MaxActiveHandles int32 // The maximum number of idle resource handles per resource location that // are kept alive by the resource pool. MaxIdleHandles uint32 // The maximum amount of time an idle resource handle can remain alive (if // specified). MaxIdleTime *time.Duration // This function creates a resource handle (e.g., a connection) for a // resource location. Open func(resourceLocation string) ( handle interface{}, err error) // This function destroys a resource handle and performs the necessary // cleanup to free up resources. Close func(handle interface{}) error // This specifies the now time function. When the function is non-nil, the // resource pool will use the specified function instead of time.Now to // generate the current time. NowFunc func() time.Time }
type ResourceLocationPool ¶
type ResourceLocationPool struct { ResourceLocation string Pool ResourcePool }
type ResourcePool ¶
type ResourcePool interface { // This returns the number of active resource handles. NumActive() int32 // This returns the number of alive idle handles. NOTE: This is only used // for testing. NumIdle() int // This associates a resource location to the resource pool; afterwhich, // the user can get resource handles for the resource location. Register(resourceLocation string) error // This dissociates a resource location from the resource pool; afterwhich, // the user can no longer get resource handles for the resource location. Unregister(resourceLocation string) error // This returns the list of registered resource location entries. ListRegistered() []string // This gets an active resource handle from the resource pool. The // handle will remain active until one of the following is called: // 1. handle.Release() // 2. handle.Discard() // 3. pool.Release(handle) // 4. pool.Discard(handle) Get(key string) (ManagedHandle, error) // This releases an active resource handle back to the resource pool. Release(handle ManagedHandle) error // This discards an active resource from the resource pool. Discard(handle ManagedHandle) error // Enter the resource pool into lame duck mode. The resource pool // will no longer return resource handles, and all idle resource handles // are closed immediately (including active resource handles that are // released back to the pool afterward). EnterLameDuckMode() }
A generic interface for managed resource pool. All resource pool implementations must be threadsafe.
func NewMultiResourcePool ¶
func NewMultiResourcePool( options Options, createPool func(Options) ResourcePool) ResourcePool
This returns a MultiResourcePool, which manages multiple resource location entries. The handles to each resource location entry acts independently.
When createPool is nil, NewSimpleResourcePool is used as default.
func NewRoundRobinResourcePool ¶
func NewRoundRobinResourcePool( options Options, createPool func(Options) ResourcePool, pools ...*ResourceLocationPool) (ResourcePool, error)
This returns a RoundRobinResourcePool.
func NewSimpleResourcePool ¶
func NewSimpleResourcePool(options Options) ResourcePool
This returns a SimpleResourcePool, where all handles are associated to a single resource location.
type RoundRobinResourcePool ¶
type RoundRobinResourcePool struct {
// contains filtered or unexported fields
}
A resource pool implementation which returns handles from the registered resource locations in a round robin fashion.
func (*RoundRobinResourcePool) Discard ¶
func (p *RoundRobinResourcePool) Discard(handle ManagedHandle) error
See ResourcePool for documentation.
func (*RoundRobinResourcePool) EnterLameDuckMode ¶
func (p *RoundRobinResourcePool) EnterLameDuckMode()
See ResourcePool for documentation.
func (*RoundRobinResourcePool) Get ¶
func (p *RoundRobinResourcePool) Get(key string) (ManagedHandle, error)
See ResourcePool for documentation.
func (*RoundRobinResourcePool) ListRegistered ¶
func (p *RoundRobinResourcePool) ListRegistered() []string
func (*RoundRobinResourcePool) NumActive ¶
func (p *RoundRobinResourcePool) NumActive() int32
See ResourcePool for documentation.
func (*RoundRobinResourcePool) NumIdle ¶
func (p *RoundRobinResourcePool) NumIdle() int
See ResourcePool for documentation.
func (*RoundRobinResourcePool) Register ¶
func (p *RoundRobinResourcePool) Register(resourceLocation string) error
See ResourcePool for documentation.
func (*RoundRobinResourcePool) Release ¶
func (p *RoundRobinResourcePool) Release(handle ManagedHandle) error
See ResourcePool for documentation.
func (*RoundRobinResourcePool) Unregister ¶
func (p *RoundRobinResourcePool) Unregister(resourceLocation string) error
See ResourcePool for documentation.
type SimpleResourcePool ¶
type SimpleResourcePool struct {
// contains filtered or unexported fields
}
A resource pool implementation where all handles are associated to the same resource location.
func (*SimpleResourcePool) Discard ¶
func (p *SimpleResourcePool) Discard(handle ManagedHandle) error
See ResourcePool for documentation.
func (*SimpleResourcePool) EnterLameDuckMode ¶
func (p *SimpleResourcePool) EnterLameDuckMode()
See ResourcePool for documentation.
func (*SimpleResourcePool) Get ¶
func (p *SimpleResourcePool) Get(unused string) (ManagedHandle, error)
This gets an active resource from the resource pool. Note that the resourceLocation argument is ignroed (The handles are associated to the resource location provided by the first Register call).
func (*SimpleResourcePool) ListRegistered ¶
func (p *SimpleResourcePool) ListRegistered() []string
func (*SimpleResourcePool) NumActive ¶
func (p *SimpleResourcePool) NumActive() int32
See ResourcePool for documentation.
func (*SimpleResourcePool) NumIdle ¶
func (p *SimpleResourcePool) NumIdle() int
See ResourcePool for documentation.
func (*SimpleResourcePool) Register ¶
func (p *SimpleResourcePool) Register(resourceLocation string) error
SimpleResourcePool can only register a single (network, address) entry. Register should be call before any Get calls.
func (*SimpleResourcePool) Release ¶
func (p *SimpleResourcePool) Release(handle ManagedHandle) error
See ResourcePool for documentation.
func (*SimpleResourcePool) Unregister ¶
func (p *SimpleResourcePool) Unregister(resourceLocation string) error
SimpleResourcePool does not support Unregister.