client

package
v0.0.0-...-ac3bb21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2013 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpApiCall

func HttpApiCall(address string, req *cheshire.Request, responseChan chan *cheshire.Response, errorChan chan error)

does an asynchrounous api call to the requested address.

func HttpApiCallSync

func HttpApiCallSync(address string, req *cheshire.Request, timeout time.Duration) (*cheshire.Response, error)

does a synchronous api call to the requested address.

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 (this *HttpClient) ApiCallSync(req *cheshire.Request, timeout time.Duration) (*cheshire.Response, error)

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) ApiCall

func (this *JsonClient) ApiCall(req *cheshire.Request, responseChan chan *cheshire.Response, errorChan chan error) error

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) Close

func (this *JsonClient) Close()

Close this client.

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) Borrow

func (this *Pool) Borrow(timeout time.Duration) (*cheshireConn, error)

checkout a connection returns an error if this pool is closed, or timeout

func (*Pool) Close

func (this *Pool) Close()

Close this pool and clean up all connections

func (*Pool) Return

func (this *Pool) Return(conn *cheshireConn)

return to the pool

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL