Documentation ¶
Index ¶
- func HttpApiCall(address string, req *cheshire.Request, responseChan chan *cheshire.Response, ...)
- func HttpApiCallSync(address string, req *cheshire.Request, timeout time.Duration) (*cheshire.Response, error)
- type Client
- type ClientCreator
- type HttpClient
- type JsonClient
- func (this *JsonClient) ApiCall(req *cheshire.Request, responseChan chan *cheshire.Response, ...) error
- func (this *JsonClient) ApiCallSync(req *cheshire.Request, timeout time.Duration) (*cheshire.Response, error)
- func (this *JsonClient) Close()
- func (this *JsonClient) Closed() bool
- func (this *JsonClient) Connect() error
- func (this *JsonClient) CurrentInFlight() int
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client interface { // Does a synchronous api call. times out after the requested timeout. // This will automatically set the txn accept to single ApiCallSync(req *cheshire.Request, timeout time.Duration) (*cheshire.Response, error) // Does an api call. ApiCall(req *cheshire.Request, responseChan chan *cheshire.Response, errorChan chan error) error //Closes this client Close() }
type ClientCreator ¶
type ClientCreator interface { //Should create and connect to a new client Create() (*cheshireConn, error) //Should clean up the connection resources //implementation should deal with Cleanup possibly being called multiple times Cleanup(*cheshireConn) }
type HttpClient ¶
type HttpClient struct {
Address string
}
func NewHttp ¶
func NewHttp(address string) *HttpClient
func (*HttpClient) ApiCall ¶
func (this *HttpClient) ApiCall(req *cheshire.Request, responseChan chan *cheshire.Response, errorChan chan error) error
Make an async api call
func (*HttpClient) ApiCallSync ¶
func (*HttpClient) Close ¶
func (this *HttpClient) Close()
type JsonClient ¶
type JsonClient struct { Host string Port int PingUri string PoolSize int //The max number of requests that can be waiting for a response. //When max inflight is reached, the client will start //blocking and waiting for room. //connection will eventually close if it waits too long. MaxInFlight int // Number of times we should retry to send a request if there is a connection problem // default is 1 Retries int //The amount of time to pause between retries // default is 500 millis RetryPause time.Duration // contains filtered or unexported fields }
Client that utilizes the json protocol and connections are static. maintains an internal connection pool.
func NewBin ¶
func NewBin(host string, port int) *JsonClient
Creates a new binary Remember to call client.Connect
func NewJson ¶
func NewJson(host string, port int) *JsonClient
Creates a new Json client Remember to call client.Connect
func (*JsonClient) ApiCallSync ¶
func (this *JsonClient) ApiCallSync(req *cheshire.Request, timeout time.Duration) (*cheshire.Response, error)
Does a synchronous api call. times out after the requested timeout. This will automatically set the txn accept to single
func (*JsonClient) Closed ¶
func (this *JsonClient) Closed() bool
func (*JsonClient) Connect ¶
func (this *JsonClient) Connect() error
Starts the json event loop and initializes one or more connections if a connection already exists it will be closed
func (*JsonClient) CurrentInFlight ¶
func (this *JsonClient) CurrentInFlight() int
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
A simple channel based pool. originally from http://www.ryanday.net/2012/09/12/golang-using-channels-for-a-connection-pool/
func NewPool ¶
func NewPool(size int, creator ClientCreator) (*Pool, error)
Creates a new pool, and initializes the clients. will fail with an error if any of the clients fail
func (*Pool) ReturnBroken ¶
func (this *Pool) ReturnBroken(conn *cheshireConn)
Returns a broken item. this item will be closed and a fresh one will be added to the pool If a new item is not able to be added to the pool (creation fails), then the broken one will be added back to the pool. This is to ensure that we always have the correct # of items in the pool