pool

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGroupNotExist returned when the group hasn't been created
	ErrGroupNotExist = errors.New("group doesn't exist")
	// ErrConnectionNotExists returned when the connection doesn't exist or has already been closed
	ErrConnectionNotExists = errors.New("connection doesn't exist")
	// ErrCouldNotAssignConnection when connection assignment fails
	ErrCouldNotAssignConnection = errors.New("assigning connection to gRPC client failed")
	// ErrInvalidConnectionPool returwhen the type assertion to ConnectionPool fails
	ErrInvalidConnectionPool = errors.New("invalid connection pool")
)
View Source
var (
	// ErrConnectionClosed is returned when the pool is closed
	ErrConnectionClosed = errors.New("connections closed")
)

Functions

This section is empty.

Types

type ClientConn

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

ClientConn holds the function created by the pool factory method. It also keeps the address, and a reference to the parent pool

func (*ClientConn) Address

func (cc *ClientConn) Address() string

Address returns the factory connection address

func (*ClientConn) Close

func (cc *ClientConn) Close() error

Close - closes the connection to the gRPC service server

func (*ClientConn) Conn

func (cc *ClientConn) Conn() FactoryConn

Conn returns the factory connection

type CloseFunc

type CloseFunc func(conn interface{}) error

CloseFunc to close the connection in the pool

type Connection

type Connection interface {
	// Address returns the connection address
	Address() string
	// Conn returns the factory connection
	Conn() FactoryConn
	// Close connection
	Close() error
}

Connection interface is the connection saved in the pool

type ConnectionPool

type ConnectionPool struct {
	CloseFunc CloseFunc

	sync.RWMutex
	// contains filtered or unexported fields
}

ConnectionPool holds the connections in the pool, alongwith the factory to create a new connection, size of each type of connection in the pool, and the CloseFunc callback used to close a specific connection in the pool

func NewPool

func NewPool(opts ...Option) *ConnectionPool

NewPool creates a new pool with size and factory

func (*ConnectionPool) Close

func (p *ConnectionPool) Close() error

Close - closes the connection pool and all it's channels

func (*ConnectionPool) Get

func (p *ConnectionPool) Get(address string) (Connection, error)

Get creates or returns an existing gRPC client connection

type Factory

type Factory func(address string) (FactoryConn, error)

Factory callback creates and returns a new connection

type FactoryConn

type FactoryConn interface{}

FactoryConn interface is the connection returned by the factory passed to the pool

type Option

type Option func(*ConnectionPool)

Option to pass as arg while creating new service

func WithCloseFunc

func WithCloseFunc(closeFunc CloseFunc) Option

WithCloseFunc passes the CloseFunc callback to the pool

func WithFactory

func WithFactory(factory Factory) Option

WithFactory defines the connection creation factory

func WithLogger

func WithLogger(logger logger.Logger) Option

WithLogger sets the logger for the pool

func WithSize

func WithSize(size int) Option

WithSize defines the size of the pool

type Pool

type Pool interface {
	// Get connection
	Get(address string) (Connection, error)
	// Close the pool
	Close() error
}

Pool interface to create new pool implementations

Jump to

Keyboard shortcuts

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