pool

package
v0.0.0-...-a906454 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_CONNECTIONS string = "max connections met"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

func NewPool

func NewPool(opts PoolOpts) *Pool

NewPool:

initialize the connection pool.
the purpose of the connection pool is to reuse connections once they have been made, minimizing overhead for reconnecting to a host every time an rpc is made.
the pool has the following structure:
	{
		[key: address/host]: Array<connections>
	}

func (*Pool) CloseConnections

func (cp *Pool) CloseConnections(addr string) (bool, error)

CloseConnections:

1.) load connections for the particular host/address
2.) if the address was loaded from the thread safe map:
	if the connection already exists in the map, close the connection
3.) remove the key from the map

func (*Pool) GetConnection

func (cp *Pool) GetConnection(addr string, port string) (*grpc.ClientConn, error)

GetConnection:

1.) load connections for the particular host/address
2.) if the address was loaded from the thread safe map:
	if the total connections in the map is greater than max connections specified throw max connections error
	otherwise for each connection in the array of connections, if the connection is not null and the connection is ready for work, return the connection
3.) if the address was not loaded, create a new grpc connection and store the new connection at the key associated with the address/host and return the new connection

for grpc connection opts, we will automatically compress the rpc on the wire

func (*Pool) PutConnection

func (cp *Pool) PutConnection(addr string, connection *grpc.ClientConn) (bool, error)

PutConnection:

1.) load connections for the particular host/address
2.) if the address was loaded from the thread safe map:
	if the connection already exists in the map, return otherwise, close the connection and return

type PoolError

type PoolError string

type PoolOpts

type PoolOpts struct {
	MaxConn int
}

Jump to

Keyboard shortcuts

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