asyncclient

package
v0.0.0-...-7847555 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: CC0-1.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallbackFunc

type CallbackFunc func(resp *Response, r binaryutil.BinaryReader, lg log.Interface) error

CallbackFunc describes a function to be called when a response arrives from the server. If the value of resp.Code is equal to serverutil.OK then further data maybe read from the server via the reader r; for any other value of resp.Code any attempt to ready from r will return io.EOF. Returning a non-nil error will cause the server connection to be dropped and placed in an error state.

type Interface

type Interface interface {
	binaryutil.ByteOrderer
	Metadata(id async.TaskID) *async.TaskMetadata
	Send(t serverutil.TaskCode, r io.Reader, f CallbackFunc) (async.TaskID, log.Interface, error)
}

Interface is the minimum interface required to send a message.

type Response

type Response struct {
	Code      serverutil.ResponseCode // The response code
	ID        async.TaskID            // The task ID
	Error     serverutil.ErrorCode    // The error code (if relevant)
	Timestamp time.Time               // The timestamp for this response
}

Response describes the task response header read from the server. The ID is the corresponding task ID, and the Timestamp is the time this response was received. The response Code will be one of serverutil.OK, serverutil.Error, or serverutil.Goodbye. If the response Code is serverutil.Error then Error will be set to the corresponding error code; for any other response Code, the value of Error is meaningless and should be ignored.

type Server

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

Server represents a client's connection to the server.

func New

func New(conn net.Conn, e binary.ByteOrder, timeout *serverutil.Timeout) *Server

New creates a new server connection using the given connection conn, byte order e, and timeout values. If timeout is nil then the default timeout durations will be used.

func (*Server) ByteOrder

func (sc *Server) ByteOrder() binary.ByteOrder

ByteOrder returns the byte order used in communication with the server.

func (*Server) Close

func (sc *Server) Close() (err error)

Close immediately closes the underlying connection to the server, and then blocks until all remaining callback functions have been called.

func (*Server) Disconnect

func (sc *Server) Disconnect(d time.Duration)

Disconnect begins a graceful disconnection, preventing new tasks from running, and scheduling a future Close on the connection after duration d has elapsed. Note that there is no way to cancel a graceful disconnection once started. If Disconnect is called again, then the final Close will be performed after the shortest of the two durations has expired. This is a non-blocking method.

func (*Server) LocalAddr

func (sc *Server) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Server) Log

func (sc *Server) Log() log.Interface

Log returns the logger.

func (*Server) Metadata

func (sc *Server) Metadata(id async.TaskID) *async.TaskMetadata

Metadata returns the metadata for the given task id, or nil if no currently assigned task has this id.

func (*Server) Metrics

func (sc *Server) Metrics() metrics.Interface

Metrics returns the metrics endpoint.

func (*Server) RemoteAddr

func (sc *Server) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

func (*Server) Send

Send submits the indicated task, with message data r, to the server. If no data needs to be sent, you may set r equal to nil. On success, the assigned task ID is returned, along with a logger for this task. The callback function f will be called asynchronously once the server returns the result of this task. If Send returns success (that is, if no error is returned) then it is guaranteed that the callback function f will eventually be called. If no callback function is required, you may set f equal to nil.

func (*Server) SetLogger

func (sc *Server) SetLogger(l log.Interface)

SetLogger sets a logger.

func (*Server) SetMetrics

func (sc *Server) SetMetrics(m metrics.Interface)

SetMetrics sets a metrics endpoint.

func (*Server) TaskCodes

func (sc *Server) TaskCodes() []serverutil.TaskCode

TaskCodes returns a slice of all assigned tasks codes. The task codes are sorted in assigned order, from oldest (at index 0) to most recent.

func (*Server) Tasks

func (sc *Server) Tasks() []async.TaskID

Tasks returns a slice of all currently assigned task ids. The ids are distinct, and sorted in increasing order.

func (*Server) Timestamp

func (sc *Server) Timestamp() time.Time

Timestamp returns the connection timestamp.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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