grpc_pool/pool_handlers.go
2017-11-09 16:43:43 +09:00

50 lines
1.0 KiB
Go

package grpc_pool
import (
"fmt"
"time"
"google.golang.org/grpc"
)
// Options is configuration of the Pool of GRpc client
type PoolHandlers struct {
MaxCapacity int
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
}
func (ph *PoolHandlers) Dial() (*grpc.ClientConn, interface{}, error) {
return nil, nil, fmt.Errorf("GRPC Pool: Dial method is not implemented")
}
func (ph *PoolHandlers) GetMaxCapacity() int {
return ph.MaxCapacity
}
func (ph *PoolHandlers) GetMaxIdle() int {
return ph.MaxIdle
}
func (ph *PoolHandlers) GetIdleTimeout() time.Duration {
return ph.IdleTimeout
}
func (ph *PoolHandlers) IsWait() bool {
return ph.Wait
}
// Validate validates the configuration
func (ph *PoolHandlers) Validate() {
if ph.IdleTimeout < 0 {
ph.IdleTimeout = DefaultIdleTimeout
}
if ph.MaxIdle < 0 {
ph.MaxIdle = DefaultMaxIdle
}
if ph.MaxCapacity <= 0 {
ph.MaxCapacity = DefaultMaxCapacity
}
}