pool

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCapacity = errors.New("invalid capacity settings")
	ErrNilConnection   = errors.New("could not put nil connection")
)
View Source
var (
	DefaultInitialCap            uint32        = 0
	DefaultMaxCap                uint32        = 20
	DefaultConnectionIdleTimeout time.Duration = time.Second * 90
	DefaultIdleTimeout           time.Duration = time.Second * 90
)
View Source
var (
	// ErrClosed is the error resulting if the pool is closed via pool.Close().
	ErrClosed = errors.New("pool is closed")
)
View Source
var (
	// ErrPoolNotFound is the error to indicate when a requested pool is not found.
	ErrPoolNotFound = errors.New("pool is not found")
)

Functions

This section is empty.

Types

type ChannelPoolOption

type ChannelPoolOption func(*channelPool)

ChannelPoolOption is a function for channel pool options.

func ChannelPoolWithConnectionIdleTimeout

func ChannelPoolWithConnectionIdleTimeout(timeout time.Duration) ChannelPoolOption

ChannelPoolWithConnectionIdleTimeout sets connection idle timeout of the pool.

func ChannelPoolWithIdleTimeout

func ChannelPoolWithIdleTimeout(timeout time.Duration) ChannelPoolOption

ChannelPoolWithIdleTimeout sets idle timeout of the pool.

func ChannelPoolWithInitialCap

func ChannelPoolWithInitialCap(capacity uint32) ChannelPoolOption

ChannelPoolWithInitialCap sets initial capability of the pool.

func ChannelPoolWithLogger

func ChannelPoolWithLogger(logger logr.Logger) ChannelPoolOption

ChannelPoolWithLogger sets the logger of the pool.

func ChannelPoolWithMaxCap

func ChannelPoolWithMaxCap(capacity uint32) ChannelPoolOption

ChannelPoolWithMaxCap sets maximum connection count of the pool.

func ChannelPoolWithName

func ChannelPoolWithName(name string) ChannelPoolOption

ChannelPoolWithName sets the name of the pool.

type Connection

type Connection interface {
	net.Conn

	// Discard closes the underlying net.Conn and mark the connection closed.
	Discard() error

	// IsClosed returns whether the connection is closed.
	IsClosed() bool

	// Acquire signals when the connection is served from the connection pool.
	Acquire()

	// Release signals when the connection is put back into the connection pool.
	Release()
}

Connection interface describes a pool connection.

type ConnectionChannel

type ConnectionChannel chan Connection

type Factory

type Factory func() (net.Conn, error)

Factory is a function to create new connections.

type Pool

type Pool interface {
	// Get returns a connection from the pool or create new one at request.
	Get() (net.Conn, error)

	// Put puts the connection back to the pool.
	Put(net.Conn) error

	// Len returns the current number of connections of the pool.
	Len() int

	// Close closes the pool and all its connections. After Close() the pool is
	// no longer usable.
	Close() error

	// IsClosed returns whether the pool is closed.
	IsClosed() bool
}

Pool interface describes a pool implementation.

func NewChannelPool

func NewChannelPool(factory Factory, opts ...ChannelPoolOption) (Pool, error)

NewChannelPool returns a new pool based on buffered channels. A new connection will be created during a Get() via the Factory(), if there is no new connection available in the pool.

type Registry

type Registry interface {
	// GetPool returns a registered pool for the given id or an error.
	GetPool(id string) (Pool, error)

	// HasPool returns whether a pool is registered with the given id.
	HasPool(id string) bool

	// AddPool registers the given pool for the given id.
	AddPool(id string, pool Pool)

	// RemovePool removes the pool registered for the given id.
	RemovePool(id string)

	// Len returns the current number of registered pools.
	Len() int

	// Close closes the registry and also every pool registered into it.
	// The registry is unusable after this call.
	Close() error

	// IsClosed returns whether the registry is closed.
	IsClosed() bool
}

Registry interface describes a pool registry.

func NewSyncMapPoolRegistry

func NewSyncMapPoolRegistry(opts ...SyncMapPoolRegistryOption) Registry

type SyncMapPoolRegistryOption

type SyncMapPoolRegistryOption func(*syncMapPoolRegistry)

SyncMapPoolRegistryOption is a function for sync map pool registry options.

func SyncMapPoolRegistryWithLogger

func SyncMapPoolRegistryWithLogger(logger logr.Logger) SyncMapPoolRegistryOption

SyncMapPoolRegistryWithLogger sets the logger of the pool.

func SyncMapPoolRegistryWithName

func SyncMapPoolRegistryWithName(name string) SyncMapPoolRegistryOption

SyncMapPoolRegistryWithName sets the name of the registry.

Jump to

Keyboard shortcuts

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