Documentation ¶
Index ¶
- Constants
- Variables
- type Conn
- type ThriftSet
- func (ts *ThriftSet) Close() error
- func (ts *ThriftSet) Event() <-chan struct{}
- func (ts *ThriftSet) GetConn() (*Conn, error)
- func (ts *ThriftSet) IdleTimeout() time.Duration
- func (ts *ThriftSet) IsClosed() bool
- func (ts *ThriftSet) MaxActivePerHost() int
- func (ts *ThriftSet) MaxIdlePerHost() int
- func (ts *ThriftSet) OpenConn(hostPort string) (io.Closer, error)
- func (ts *ThriftSet) SetIdleTimeout(t time.Duration)
- func (ts *ThriftSet) SetMaxActivePerHost(max int)
- func (ts *ThriftSet) SetMaxIdlePerHost(max int)
- func (ts *ThriftSet) SetTimeout(t time.Duration)
- func (ts *ThriftSet) Timeout() time.Duration
- type Watcher
Constants ¶
const ( DefaultMaxIdlePerHost = 10 DefaultMaxActivePerHost = 10 DefaultTimeout = time.Second DefaultIdleTimeout = 5 * time.Minute )
Default values for ThriftSet parameters
Variables ¶
var ( // ErrNoEndpoints is returned when no endpoints are configured or available. ErrNoEndpoints = errors.New("thriftset: no endpoints configured or available") // ErrGetOnClosedSet is returned when requesting a connection from a closed thrift set. ErrGetOnClosedSet = errors.New("thriftset: get on closed set") // ErrGetOnClosedEndpoint is returned by endpoint.GetConn if the endpoint // has been closed because it was removed from the watch. // This error is retryable. ErrGetOnClosedEndpoint = errors.New("endpoint closed") )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { Socket *thrift.TSocket // used to create new clients Client interface{} // a place to cache thrift clients. // contains filtered or unexported fields }
Conn is the connection returned by the pool.
type ThriftSet ¶
type ThriftSet struct { LastEvent time.Time EventCount int // contains filtered or unexported fields }
ThriftSet defines a set of thift connections. It loadbalances over the set of hosts using the "least active connections" strategy.
func (*ThriftSet) Close ¶
Close releases the resources used by the set. ie. closes all connections. There may still be connections in flight when this function returns.
func (*ThriftSet) Event ¶
func (ts *ThriftSet) Event() <-chan struct{}
Event returns the event channel. This channel will get an object whenever something changes with the list of endpoints. Mostly used for testing as this will trigger after all the watch events handling completes.
func (*ThriftSet) GetConn ¶
GetConn will create a connection or return one from the idle list. It will use a host from the Watcher with the least ammount of active connections.
func (*ThriftSet) IdleTimeout ¶
IdleTimeout returns the timeout for connections to live in the idle pool. This is part of the endpoints.Pooler interface.
func (*ThriftSet) IsClosed ¶
IsClosed returns true if the set has been closed. There still might be active connections in flight but they will be closed as they are released.
func (*ThriftSet) MaxActivePerHost ¶
MaxActivePerHost returna the max active connections for a given host. This is part of the endpoints.Pooler interface.
func (*ThriftSet) MaxIdlePerHost ¶
MaxIdlePerHost returns the max number of idle connections to keep in the pool. This is part of the endpoints.Pooler interface.
func (*ThriftSet) OpenConn ¶
OpenConn creats a new thrift socket for the host. This is used by the endpoints.Set to create connections for a given endpoint. This is part of the endpoints.Pooler interface.
func (*ThriftSet) SetIdleTimeout ¶
SetIdleTimeout sets the amount of time a connection can live in the idle pool.
func (*ThriftSet) SetMaxActivePerHost ¶
SetMaxActivePerHost sets the max number of active connections to a given endpoint.
func (*ThriftSet) SetMaxIdlePerHost ¶
SetMaxIdlePerHost sets the max number of connections in the idle pool.
func (*ThriftSet) SetTimeout ¶
SetTimeout sets the thrift request timeout for new connections in the pool. This should be set at startup, as existing/live connections will not be updated with these new values.