2016-03-12 11:52:13 +03:00
|
|
|
package pool
|
|
|
|
|
2020-08-15 15:36:02 +03:00
|
|
|
import "context"
|
2019-08-03 17:21:12 +03:00
|
|
|
|
2016-03-12 11:52:13 +03:00
|
|
|
type SingleConnPool struct {
|
2020-08-15 15:36:02 +03:00
|
|
|
pool Pooler
|
|
|
|
cn *Conn
|
|
|
|
stickyErr error
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
|
2016-03-14 14:17:33 +03:00
|
|
|
var _ Pooler = (*SingleConnPool)(nil)
|
|
|
|
|
2020-08-15 15:36:02 +03:00
|
|
|
func NewSingleConnPool(pool Pooler, cn *Conn) *SingleConnPool {
|
|
|
|
return &SingleConnPool{
|
|
|
|
pool: pool,
|
|
|
|
cn: cn,
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-18 17:03:32 +03:00
|
|
|
func (p *SingleConnPool) NewConn(ctx context.Context) (*Conn, error) {
|
|
|
|
return p.pool.NewConn(ctx)
|
2017-04-17 15:43:58 +03:00
|
|
|
}
|
|
|
|
|
2019-08-03 17:21:12 +03:00
|
|
|
func (p *SingleConnPool) CloseConn(cn *Conn) error {
|
|
|
|
return p.pool.CloseConn(cn)
|
2017-04-17 15:43:58 +03:00
|
|
|
}
|
|
|
|
|
2019-08-18 17:03:32 +03:00
|
|
|
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error) {
|
2020-08-15 15:36:02 +03:00
|
|
|
if p.stickyErr != nil {
|
|
|
|
return nil, p.stickyErr
|
2019-08-02 00:59:53 +03:00
|
|
|
}
|
2020-08-15 15:36:02 +03:00
|
|
|
return p.cn, nil
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
|
2020-08-15 15:36:02 +03:00
|
|
|
func (p *SingleConnPool) Put(ctx context.Context, cn *Conn) {}
|
2019-08-03 17:21:12 +03:00
|
|
|
|
2020-08-15 15:36:02 +03:00
|
|
|
func (p *SingleConnPool) Remove(ctx context.Context, cn *Conn, reason error) {
|
|
|
|
p.cn = nil
|
|
|
|
p.stickyErr = reason
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
|
2020-08-15 15:36:02 +03:00
|
|
|
func (p *SingleConnPool) Close() error {
|
|
|
|
p.cn = nil
|
|
|
|
p.stickyErr = ErrClosed
|
|
|
|
return nil
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *SingleConnPool) Len() int {
|
2020-08-15 15:36:02 +03:00
|
|
|
return 0
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
|
2018-05-28 17:27:24 +03:00
|
|
|
func (p *SingleConnPool) IdleLen() int {
|
2020-08-15 15:36:02 +03:00
|
|
|
return 0
|
2016-03-12 11:52:13 +03:00
|
|
|
}
|
|
|
|
|
2016-10-02 15:44:01 +03:00
|
|
|
func (p *SingleConnPool) Stats() *Stats {
|
2019-08-03 17:21:12 +03:00
|
|
|
return &Stats{}
|
2016-03-14 14:17:33 +03:00
|
|
|
}
|