client

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const TRACE_INFO_TIME_FORMAT = "Mon Jan _2 15:04:05.999 2006"

Variables

This section is empty.

Functions

func FormatTraceInfo

func FormatTraceInfo(ti *proto.TraceInfo, indent int) string

Formats the TraceInfo data structure.

Types

type AsyncClient

type AsyncClient struct {
	// contains filtered or unexported fields
}

func NewAsyncClient

func NewAsyncClient(client_name string, addr PeerAddress, queue_length uint,
	security_manager *smgr.ClientSecurityManager) (*AsyncClient, error)

Create an asynchronous client. An AsyncClient is also called using Request(), but it queues the request (in a buffered channel with the length queue_length). The requests themselves are sent synchronously (REQ/REP), but the Request() function returns immediately if the channel queue is not full yet. The queuing avoids a too high CPU use on both server and client; higher parallelism can simply be achieved by using multiple AsyncClients.

client_name is an arbitrary name that can be used to identify this client at the server (e.g. in logs)

func (*AsyncClient) Close

func (cl *AsyncClient) Close()

func (*AsyncClient) Request

func (cl *AsyncClient) Request(data []byte, service, endpoint string, cb Callback)

func (*AsyncClient) SetTimeout

func (cl *AsyncClient) SetTimeout(d time.Duration)

Set timeout for writes.

type Callback

type Callback func([]byte, error)

type Client

type Client struct {
	// contains filtered or unexported fields
}

A client contains a channel and some metadata, a state machine, and a stack of client filters.

func New

func New(name string, channel *RpcChannel) Client

Creates a new client from the channel. Don't share a channel among two concurrently active clients.

func NewClient

func NewClient(name string, channel *RpcChannel) Client

NewClient is deprecated; use New()

func (*Client) Destroy

func (client *Client) Destroy()

Disconnects the channel and disables the client

func (*Client) IsHealthy

func (client *Client) IsHealthy() bool

Sends a request to the server, asking whether it accepts requests and testing general connectivity. Uses a timeout of 1 second.

func (*Client) IsHealthyWithin

func (client *Client) IsHealthyWithin(d time.Duration) bool

Same as IsHealthy(), but with a configurable timeout

func (*Client) NewRequest

func (client *Client) NewRequest(service, endpoint string) *Request

Create a Request to be sent by this client. If a previous request has not been finished, this method returns nil!

func (*Client) Request

func (cl *Client) Request(data []byte, service, endpoint string, trace_dest *proto.TraceInfo) ([]byte, error)

Oneshot-API: Send a request with raw data to the connected RPC server.

func (*Client) RequestProtobuf

func (cl *Client) RequestProtobuf(request, reply pb.Message, service, endpoint string, trace_dest *proto.TraceInfo) error

Oneshot-API: Send a request with the given protocol buffers to the connected RPC server.

func (*Client) SetTimeout

func (client *Client) SetTimeout(d time.Duration, propagate bool)

Set socket timeout (default 10s) and whether to propagate this timeout through the call tree.

type ClientFilter

type ClientFilter (func(rq *Request, next_filter int) Response)

A ClientFilter is a function that is called with a request and fulfills a certain task. Filters are stacked in Client.filters; filters[0] is called first, and calls in turn filters[1] until the last filter sends the message off to the network.

type ConnectionCache

type ConnectionCache struct {
	// contains filtered or unexported fields
}

ConnectionCache is a pool of RPC connections. Applications call Connect() and get, transparently, either a cached connection or a newly created one. After being finished with using the connection, the application should call Return() with the connection if it wants to use it later again.

func NewConnCache

func NewConnCache(client_name string) *ConnectionCache

func (*ConnectionCache) CleanOld

func (cc *ConnectionCache) CleanOld(older_than time.Duration)

Remove and close all connections from the pool that are older than time.Now() - older_than. Also cleans up empty cache entries.

func (*ConnectionCache) CloseAll

func (cc *ConnectionCache) CloseAll()

Closes all connections

func (*ConnectionCache) Connect

func (cc *ConnectionCache) Connect(peer PeerAddress,
	security_manager *smgr.ClientSecurityManager) (*Client, error)

Get a connection, either from the pool or a new one, depending on if there are connections available.

func (*ConnectionCache) Return

func (cc *ConnectionCache) Return(clp **Client)

Return a connection into the pool. Argument is a pointer to a pointer to make sure that the client is not used by the calling function after this call.

type PeerAddress

type PeerAddress struct {
	// contains filtered or unexported fields
}

A TCP/IP or Unix socket address

func IPCPeer

func IPCPeer(path string) PeerAddress

Construct a peer address for a unix socket peer.

func Peer

func Peer(host string, port uint) PeerAddress

Construct a new peer address.

func (*PeerAddress) GoString

func (pa *PeerAddress) GoString() string

func (*PeerAddress) String

func (pa *PeerAddress) String() string

func (*PeerAddress) ToUrl

func (pa *PeerAddress) ToUrl() string

Convert a PeerAddress to a ZeroMQ URL.

type Request

type Request struct {
	// contains filtered or unexported fields
}

An RPC request that can be modified before it is sent.

func (*Request) Go

func (r *Request) Go(payload []byte) Response

Send a request.

func (*Request) GoProto

func (r *Request) GoProto(msg pb.Message) Response

Send a request with a serialized protocol buffer

func (*Request) SetContext

func (r *Request) SetContext(c *server.Context) *Request

func (*Request) SetParameters

func (r *Request) SetParameters(p *RequestParams) *Request

func (*Request) SetTrace

func (r *Request) SetTrace(t *proto.TraceInfo) *Request

type RequestParams

type RequestParams struct {
	// contains filtered or unexported fields
}

Various parameters determining how a request is executed. There are builder methods to set the various parameters.

func NewParams

func NewParams() *RequestParams

func (*RequestParams) AcceptRedirects

func (p *RequestParams) AcceptRedirects(b bool) *RequestParams

Whether to follow redirects issued by the server. May impact efficiency.

func (*RequestParams) DeadlinePropagation

func (p *RequestParams) DeadlinePropagation(b bool) *RequestParams

Whether to enable deadline propagation; that is, tell the server the time beyond which it doesn't need to bother returning a response.

func (*RequestParams) Retries

func (p *RequestParams) Retries(r uint) *RequestParams

How often a request is to be retried. Default: 0

func (*RequestParams) Timeout

func (p *RequestParams) Timeout(d time.Duration) *RequestParams

Set the timeout; this is used as network timeout and for the deadline propagation, if enabled.

type Response

type Response struct {
	// contains filtered or unexported fields
}

func DebugFilter

func DebugFilter(rq *Request, next int) Response

func RedirectFilter

func RedirectFilter(rq *Request, next int) Response

Implements redirects: A server can tell us to follow a redirect. This is expensive in general because it involves setting up and tearing down a completely new client. It also doesn't work well with security-enabled RPCs.

func RetryFilter

func RetryFilter(rq *Request, next int) Response

A filter that retries a request according to the request's parameters.

func SendFilter

func SendFilter(rq *Request, next int) Response

Send a request and wait for it to complete. Must be the last filter in the stack

func TimeoutFilter

func TimeoutFilter(rq *Request, next int) Response

Sets appropriate timeouts on the socket, only for this request

func TraceMergeFilter

func TraceMergeFilter(rq *Request, next int) Response

Appends the received trace info to context or requested trace.

func (*Response) Error

func (rp *Response) Error() string

Get the error that has occurred.

Special codes are returned for RPC errors, which start with prefix "RPC:" and a code from the proto/rpc.proto enum RPCResponse.

func (*Response) GetResponseMessage

func (rp *Response) GetResponseMessage(msg pb.Message) error

Unmarshals the response into msg.

func (*Response) Ok

func (rp *Response) Ok() bool

Check whether the request was successful.

func (*Response) Payload

func (rp *Response) Payload() []byte

Returns the response payload.

type RpcChannel

type RpcChannel struct {
	// contains filtered or unexported fields
}

A channel to an RPC server. It is threadsafe, but should not be shared among multiple clients.

TODO(lbo): Think about implementing a channel on top of DEALER, with a background goroutine delivering results to waiting requests.

func NewChannelAndConnect

func NewChannelAndConnect(addr PeerAddress, security_manager *smgr.ClientSecurityManager) (*RpcChannel, error)

NewChannelAndConnect creates a new channel and connects it to `addr`.

func NewRpcChannel

func NewRpcChannel(security_manager *smgr.ClientSecurityManager) (*RpcChannel, error)

Create a new RpcChannel. security_manager may be nil.

func (*RpcChannel) Connect

func (c *RpcChannel) Connect(addr PeerAddress) error

Connect channel to adr. (This adds the server to the set of connections of this channel; connections are used in a round-robin fashion)

func (*RpcChannel) Disconnect

func (c *RpcChannel) Disconnect(peer PeerAddress)

Disconnect the given peer (i.e., take it out of the connection pool)

func (*RpcChannel) Reconnect

func (c *RpcChannel) Reconnect()

First disconnect, then reconnect to all peers.

func (*RpcChannel) SetTimeout

func (c *RpcChannel) SetTimeout(d time.Duration)

Set send/receive timeout on this channel.

Jump to

Keyboard shortcuts

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