pool

package module
v0.0.0-...-31c709b Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2021 License: MIT Imports: 7 Imported by: 0

README ΒΆ

Rpool πŸ’

Go connection pool implemented by circular linked list(in go we call it ringπŸ’)

Basically it makes all connections in pool work simultaneously and it can be used to manage and reuse connections.

Go Report Card

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var (
	ErrExceedMaxPoolLimit = errors.New("exceed max pool limit")
)

Functions ΒΆ

This section is empty.

Types ΒΆ

type Client ΒΆ

type Client struct {
	Service string
	Pool    RPool
}

func (*Client) GetClient ΒΆ

func (c *Client) GetClient() (client interface{}, df func(), err error)

type Connection ΒΆ

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

func NewConnection ΒΆ

func NewConnection(pool RPool, client interface{}, version int64) *Connection

func (*Connection) ClearSession ΒΆ

func (conn *Connection) ClearSession()

func (*Connection) Close ΒΆ

func (conn *Connection) Close() error

func (*Connection) GetClient ΒΆ

func (conn *Connection) GetClient() interface{}

func (*Connection) GetCreateTime ΒΆ

func (conn *Connection) GetCreateTime() time.Time

func (*Connection) GetPool ΒΆ

func (conn *Connection) GetPool() RPool

func (*Connection) GetSession ΒΆ

func (conn *Connection) GetSession() interface{}

func (*Connection) GetUsage ΒΆ

func (conn *Connection) GetUsage() int64

func (*Connection) GetVersion ΒΆ

func (conn *Connection) GetVersion() int64

func (*Connection) HandleClose ΒΆ

func (conn *Connection) HandleClose(_close func() error)

func (*Connection) HandleIsClosed ΒΆ

func (conn *Connection) HandleIsClosed(isClosed func() bool)

func (*Connection) HandleReset ΒΆ

func (conn *Connection) HandleReset(reset func() error)

func (*Connection) IncrUsage ΒΆ

func (conn *Connection) IncrUsage()

func (*Connection) IsClosed ΒΆ

func (conn *Connection) IsClosed() bool

func (*Connection) Reset ΒΆ

func (conn *Connection) Reset() error

func (*Connection) SetSession ΒΆ

func (conn *Connection) SetSession(session interface{})

type Pool ΒΆ

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

func (*Pool) Acquire ΒΆ

func (pool *Pool) Acquire() (conn RConnection, err error)

func (*Pool) Capacity ΒΆ

func (pool *Pool) Capacity() int

func (*Pool) GetDescription ΒΆ

func (pool *Pool) GetDescription() string

func (*Pool) GetDomain ΒΆ

func (pool *Pool) GetDomain() string

func (*Pool) GetPayload ΒΆ

func (pool *Pool) GetPayload() interface{}

func (*Pool) GetVersion ΒΆ

func (pool *Pool) GetVersion() int64

func (*Pool) IncrVersion ΒΆ

func (pool *Pool) IncrVersion()

func (*Pool) Len ΒΆ

func (pool *Pool) Len() int

func (*Pool) Release ΒΆ

func (pool *Pool) Release(conn RConnection)

func (*Pool) SetCapacity ΒΆ

func (pool *Pool) SetCapacity(limit int)

func (*Pool) SetConnExpire ΒΆ

func (pool *Pool) SetConnExpire(expire time.Duration)

func (*Pool) SetConnMaxUsage ΒΆ

func (pool *Pool) SetConnMaxUsage(usage int64)

func (*Pool) SetDescription ΒΆ

func (pool *Pool) SetDescription(description string)

func (*Pool) SetDropConnThreshold ΒΆ

func (pool *Pool) SetDropConnThreshold(threshold float64)

func (*Pool) SetPayload ΒΆ

func (pool *Pool) SetPayload(payload interface{})

type RConnection ΒΆ

type RConnection interface {
	GetUsage() int64
	GetPool() RPool
	GetVersion() int64
	GetClient() interface{}
	SetSession(interface{})
	GetSession() interface{}
	GetCreateTime() time.Time
	IncrUsage()
	Close() error
	Reset() error
	IsClosed() bool
	HandleClose(func() error)
	HandleReset(func() error)
	HandleIsClosed(func() bool)
}

type RPool ΒΆ

type RPool interface {
	GetDomain() string
	Acquire() (RConnection, error)
	Release(RConnection)
	GetPayload() interface{}
	SetPayload(interface{})
	GetDescription() string
	SetDescription(string)
	GetVersion() int64
	IncrVersion()
	SetConnExpire(time.Duration)
	SetConnMaxUsage(int64)
	SetDropConnThreshold(float64)
	Len() int
	Capacity() int
	SetCapacity(int)
}

func NewPool ΒΆ

func NewPool(domain string, limit int, factory func(RPool) (RConnection, error)) RPool

type Ring ΒΆ

type Ring struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewRing ΒΆ

func NewRing() *Ring

func (*Ring) Len ΒΆ

func (r *Ring) Len() int

func (*Ring) Pop ΒΆ

func (r *Ring) Pop() (conn RConnection)

func (*Ring) Push ΒΆ

func (r *Ring) Push(conn RConnection)

type Statistics ΒΆ

type Statistics struct {
	ReleaseCount int64
	AcquireCount int64
}

Jump to

Keyboard shortcuts

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