grpc_pool/pool_handlers.go

50 lines
1.0 KiB
Go
Raw Normal View History

2017-11-09 15:47:07 +09:00
package grpc_pool
2017-09-05 14:42:54 +09:00
import (
2017-11-09 15:47:07 +09:00
"fmt"
2017-09-05 14:42:54 +09:00
"time"
"google.golang.org/grpc"
)
// Options is configuration of the Pool of GRpc client
type PoolHandlers struct {
MaxCapacity int
2017-11-09 16:43:43 +09:00
MaxIdle int
IdleTimeout time.Duration
// If Wait is true and the pool is at the MaxActive limit, then Get() waits
// for a connection to be returned to the pool before returning.
Wait bool
2017-09-05 14:42:54 +09:00
}
2017-11-09 15:47:07 +09:00
func (ph *PoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) {
return nil, nil, fmt.Errorf("GRPC Pool: Dial method is not implemented")
2017-11-09 14:46:04 +09:00
}
2017-11-09 16:43:43 +09:00
func (ph *PoolHandlers) GetMaxCapacity() int {
return ph.MaxCapacity
2017-09-05 14:42:54 +09:00
}
2017-11-09 15:47:07 +09:00
func (ph *PoolHandlers) GetMaxIdle() int {
return ph.MaxIdle
2017-09-05 14:42:54 +09:00
}
2017-11-09 16:43:43 +09:00
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
return ph.IdleTimeout
}
func (ph *PoolHandlers) IsWait() bool {
return ph.Wait
2017-09-05 14:42:54 +09:00
}
// Validate validates the configuration
2017-11-09 15:47:07 +09:00
func (ph *PoolHandlers) Validate() {
if ph.IdleTimeout < 0 {
ph.IdleTimeout = DefaultIdleTimeout
2017-09-05 14:42:54 +09:00
}
2017-11-09 15:47:07 +09:00
if ph.MaxIdle < 0 {
ph.MaxIdle = DefaultMaxIdle
2017-09-05 14:42:54 +09:00
}
2017-11-09 15:47:07 +09:00
if ph.MaxCapacity <= 0 {
ph.MaxCapacity = DefaultMaxCapacity
2017-09-05 14:42:54 +09:00
}
}