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 {
|
|
|
|
IdleTimeout time.Duration
|
|
|
|
MaxIdle int
|
|
|
|
MaxCapacity int
|
|
|
|
}
|
|
|
|
|
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 15:47:07 +09:00
|
|
|
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
|
|
|
|
return ph.IdleTimeout
|
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 15:47:07 +09:00
|
|
|
func (ph *PoolHandlers) GetMaxCapacity() int {
|
|
|
|
return ph.MaxCapacity
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|