pool

package
v0.0.52 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDialRetryCount    = 3
	DefaultRetryInterval     = time.Second * 10
	DefaultKeepAliveInterval = time.Second * 3
	DefaultCreateNewInterval = time.Second * 1
	DefaultCleanInterval     = time.Second * 60
)

Functions

func ErrWrapper

func ErrWrapper(err Err, ps ...string) error

Types

type Config added in v0.0.52

type Config struct {
	PoolType          Type
	Address           string
	Port              string
	Dial              func(ctx context.Context, address, port string) (connection interface{}, err error)
	Close             func(ctx context.Context, connection interface{}) (err error)
	KeepAlive         func(ctx context.Context, connection interface{}) (err error)
	InitialPoolSize   int
	BestPoolSize      int
	MaxPoolSize       int
	DialRetryCount    int
	KeepAliveInterval time.Duration
	CleanInterval     time.Duration
	DialRetryInterval time.Duration
	CreateNewInterval time.Duration
	Logger            log.Log
}

type Err

type Err int
const (
	UnknownErrCode    Err = iota
	IllegalParams         // illegal params
	GetConnTimeout        // Get Connection Timeout
	ResourceExhausted     // Pool Was Exhausted
)

func (Err) String

func (i Err) String() string

type ExclusivePool

type ExclusivePool struct {
	Address           string
	Port              string
	Dial              func(ctx context.Context, address, port string) (connection interface{}, err error)
	Close             func(ctx context.Context, connection interface{}) (err error)
	KeepAlive         func(ctx context.Context, connection interface{}) (err error)
	InitialPoolSize   int
	BestPoolSize      int
	MaxPoolSize       int
	DialRetryCount    int
	KeepAliveInterval time.Duration
	CleanInterval     time.Duration
	DialRetryInterval time.Duration
	Logger            log.Log
	// contains filtered or unexported fields
}

func NewExclusivePool

func NewExclusivePool(ctx context.Context, cfg *Config) (*ExclusivePool, error)

func (*ExclusivePool) Get

func (p *ExclusivePool) Get() (connection interface{}, err error)

func (*ExclusivePool) Put

func (p *ExclusivePool) Put(connection interface{}) (err error)

func (*ExclusivePool) Release

func (p *ExclusivePool) Release()

type OptionFunc

type OptionFunc func(*Config)

func WithAddress

func WithAddress(Address string) OptionFunc

func WithBestPoolSize

func WithBestPoolSize(BestPoolSize int) OptionFunc

func WithCleanInterval

func WithCleanInterval(CleanInterval time.Duration) OptionFunc

func WithClose

func WithClose(Close func(ctx context.Context, connection interface{}) (err error)) OptionFunc

func WithCreateNewInterval

func WithCreateNewInterval(CreateNewInterval time.Duration) OptionFunc

func WithDial

func WithDial(Dial func(ctx context.Context, address, port string) (connection interface{}, err error)) OptionFunc

func WithDialRetryCount

func WithDialRetryCount(DialRetryCount int) OptionFunc

func WithDialRetryInterval

func WithDialRetryInterval(DialRetryInterval time.Duration) OptionFunc

func WithInitialPoolSize

func WithInitialPoolSize(InitialPoolSize int) OptionFunc

func WithKeepAlive

func WithKeepAlive(KeepAlive func(ctx context.Context, connection interface{}) (err error)) OptionFunc

func WithKeepAliveInterval

func WithKeepAliveInterval(KeepAliveInterval time.Duration) OptionFunc

func WithLogger

func WithLogger(Logger log.Log) OptionFunc

func WithMaxPoolSize

func WithMaxPoolSize(MaxPoolSize int) OptionFunc

func WithPort

func WithPort(Port string) OptionFunc

func WithType

func WithType(poolType Type) OptionFunc

type Pool

type Pool interface {
	Get() (connection interface{}, err error)
	Put(connection interface{}) (err error)
	Release()
}

func NewPool

func NewPool(ctx context.Context, opts ...OptionFunc) (Pool, error)

type SharePool

type SharePool struct {
	Address           string
	Port              string
	Dial              func(ctx context.Context, address, port string) (connection interface{}, err error)
	Close             func(ctx context.Context, connection interface{}) (err error)
	KeepAlive         func(ctx context.Context, connection interface{}) (err error)
	InitialPoolSize   int
	DialRetryCount    int
	KeepAliveInterval time.Duration
	CleanInterval     time.Duration
	DialRetryInterval time.Duration
	CreateNewInterval time.Duration
	Logger            log.Log
	// contains filtered or unexported fields
}

func NewSharePool

func NewSharePool(ctx context.Context, cfg *Config) (*SharePool, error)

func (*SharePool) Get

func (s *SharePool) Get() (connection interface{}, err error)

func (*SharePool) Put

func (s *SharePool) Put(_ interface{}) (err error)

func (*SharePool) Release

func (s *SharePool) Release()

type Type

type Type int
const (
	Exclusive Type = iota
	Share
)

Jump to

Keyboard shortcuts

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