connpool

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NowFunc = time.Now // for testing

)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Err  error       // whether the conn is error
	Inst interface{} // conn instance
	// contains filtered or unexported fields
}

type ConnPool

type ConnPool struct {
	Connect      func() (interface{}, error) // connect func,return instance,id,error
	DisConnect   func(c interface{})         // disconnect func
	ClearConnect func(c interface{})         // clear connect data

	// must init param
	// Maximum number of connections allocated by the pool at a given time.
	// When zero, there is no limit on the number of connections in the pool.
	MaxActiveNum int

	// Reserved idle connections
	ReservedIdleNum int

	// Close connections after remaining idle for this duration. If the value
	// is zero, then idle connections are not closed. Applications should set
	// the timeout to a value less than the server's timeout.
	IdleTimeout time.Duration

	// How many seconds wait for when the pool is at the MaxActiveNum limit
	// 0 forever,-1 no wait
	WaitTime int64
	// contains filtered or unexported fields
}

func NewConnectionPool

func NewConnectionPool(maxActiveNum int, revIdleNum int, idleTimeout time.Duration, waitTime int64, connectFunc func() (interface{}, error), disConnectFunc func(interface{}), clearConnectFunc func(interface{})) *ConnPool

new connection pool

func (*ConnPool) ClearPool

func (p *ConnPool) ClearPool()

func (*ConnPool) GetActiveNum

func (p *ConnPool) GetActiveNum() int

func (*ConnPool) GetIdleNum

func (p *ConnPool) GetIdleNum() int

func (*ConnPool) GetWaitNum

func (p *ConnPool) GetWaitNum() int

func (*ConnPool) Pop

func (p *ConnPool) Pop() (*Conn, error)

pop an connection from pool

func (*ConnPool) Push

func (p *ConnPool) Push(c *Conn) error

push an connection to pool. (you shoud not op c after push the conn to pool)

type TMOCond

type TMOCond struct {
	L sync.Locker
	// contains filtered or unexported fields
}

func NewTMOCond

func NewTMOCond(l sync.Locker) *TMOCond

func (*TMOCond) Broadcast

func (t *TMOCond) Broadcast()

func (*TMOCond) Signal

func (t *TMOCond) Signal()

func (*TMOCond) Wait

func (t *TMOCond) Wait()

func (*TMOCond) WaitOrTimeout

func (t *TMOCond) WaitOrTimeout(d time.Duration) bool

Jump to

Keyboard shortcuts

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