connpool

package
v0.9.3-dep2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Overview

Package connpool provide short connection and long connection pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetReporter

func SetReporter(r Reporter)

SetReporter set the common reporter of connection pool, that can only be set once.

Types

type ConnWithPkgSize

type ConnWithPkgSize struct {
	net.Conn
	Written int32
	Readn   int32
}

ConnWithPkgSize wraps a connection and records the bytes read or written through it.

func (*ConnWithPkgSize) Close

func (c *ConnWithPkgSize) Close() error

Close implements the net.Conn interface.

func (*ConnWithPkgSize) Read

func (c *ConnWithPkgSize) Read(b []byte) (n int, err error)

Read implements the net.Conn interface.

func (*ConnWithPkgSize) Write

func (c *ConnWithPkgSize) Write(b []byte) (n int, err error)

Write implements the net.Conn interface.

type ConnectionPoolType

type ConnectionPoolType int8

ConnectionPoolType is the type of connection pool.

const (
	Short ConnectionPoolType = iota
	Long
)

Short and Long flags define which indicates type of connection pool..

type DummyPool

type DummyPool struct{}

DummyPool is a dummy implementation of remote.ConnPool.

func (*DummyPool) Clean

func (p *DummyPool) Clean(network, address string)

Clean implements the remote.LongConnPool interface.

func (*DummyPool) Close

func (p *DummyPool) Close() error

Close is to release resource of ConnPool, it is executed when client is closed.

func (*DummyPool) Discard

func (p *DummyPool) Discard(conn net.Conn) error

Discard implements the remote.ConnPool interface.

func (*DummyPool) Get

func (p *DummyPool) Get(ctx context.Context, network, address string, opt remote.ConnOption) (net.Conn, error)

Get implements the remote.ConnPool interface.

func (*DummyPool) Put

func (p *DummyPool) Put(conn net.Conn) error

Put implements the remote.ConnPool interface.

type DummyReporter

type DummyReporter struct{}

DummyReporter is a dummy implementation of Reporter.

func (*DummyReporter) ConnFailed

func (dcm *DummyReporter) ConnFailed(poolType ConnectionPoolType, serviceName string, addr net.Addr)

ConnFailed implements the Reporter interface.

func (*DummyReporter) ConnSucceed

func (dcm *DummyReporter) ConnSucceed(poolType ConnectionPoolType, serviceName string, addr net.Addr)

ConnSucceed implements the Reporter interface.

func (*DummyReporter) ReuseSucceed

func (dcm *DummyReporter) ReuseSucceed(poolType ConnectionPoolType, serviceName string, addr net.Addr)

ReuseSucceed implements the Reporter interface.

type LongPool

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

LongPool manages a pool of long connections.

func NewLongPool

func NewLongPool(serviceName string, idlConfig connpool.IdleConfig) *LongPool

NewLongPool creates a long pool using the given IdleConfig.

func (*LongPool) Clean

func (lp *LongPool) Clean(network, address string)

Clean implements the LongConnPool interface.

func (*LongPool) Close

func (lp *LongPool) Close() error

Close releases all peers in the pool, it is executed when client is closed.

func (*LongPool) Discard

func (lp *LongPool) Discard(conn net.Conn) error

Discard implements the ConnPool interface.

func (*LongPool) Dump

func (lp *LongPool) Dump() interface{}

Dump is used to dump current long pool info when needed, like debug query.

func (*LongPool) EnableReporter

func (lp *LongPool) EnableReporter()

EnableReporter enable reporter for long connection pool.

func (*LongPool) Evict added in v0.4.3

func (lp *LongPool) Evict()

Evict cleanups the idle connections in peers.

func (*LongPool) Get

func (lp *LongPool) Get(ctx context.Context, network, address string, opt remote.ConnOption) (net.Conn, error)

Get pick or generate a net.Conn and return The context is not used but leave it for now.

func (*LongPool) Put

func (lp *LongPool) Put(conn net.Conn) error

Put implements the ConnPool interface.

func (*LongPool) Tick added in v0.5.0

func (lp *LongPool) Tick()

Tick implements the interface utils.TickerTask.

func (*LongPool) WarmUp added in v0.3.0

WarmUp implements the warmup.Pool interface.

type PoolDump added in v0.4.3

type PoolDump struct {
	IdleNum       int         `json:"idle_num"`
	ConnsDeadline []time.Time `json:"conns_deadline"`
}

type Reporter

type Reporter interface {
	ConnSucceed(poolType ConnectionPoolType, serviceName string, addr net.Addr)
	ConnFailed(poolType ConnectionPoolType, serviceName string, addr net.Addr)
	ReuseSucceed(poolType ConnectionPoolType, serviceName string, addr net.Addr)
}

Reporter report status of connection pool.

func GetCommonReporter added in v0.3.0

func GetCommonReporter() Reporter

GetCommonReporter returns the current Reporter used by connection pools.

type ShortPool

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

ShortPool is the conn pool for short connections.

func NewShortPool

func NewShortPool(serviceName string) *ShortPool

NewShortPool timeout is connection timeout.

func (*ShortPool) Close

func (p *ShortPool) Close() error

Close is to release resource of ConnPool, it is executed when client is closed. ShortPool do nothing

func (*ShortPool) Discard

func (p *ShortPool) Discard(conn net.Conn) error

Discard implements the ConnPool interface.

func (*ShortPool) EnableReporter

func (p *ShortPool) EnableReporter()

EnableReporter enable reporter for short connection pool.

func (*ShortPool) Get

func (p *ShortPool) Get(ctx context.Context, network, address string, opt remote.ConnOption) (net.Conn, error)

Get return a PoolConn instance which implement net.Conn interface.

func (*ShortPool) Put

func (p *ShortPool) Put(conn net.Conn) error

Put implements the ConnPool interface.

Jump to

Keyboard shortcuts

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