Documentation ¶
Index ¶
- type CallbackFunc
- type Interface
- type Response
- type Server
- func (sc *Server) ByteOrder() binary.ByteOrder
- func (sc *Server) Close() (err error)
- func (sc *Server) Disconnect(d time.Duration)
- func (sc *Server) LocalAddr() net.Addr
- func (sc *Server) Log() log.Interface
- func (sc *Server) Metadata(id async.TaskID) *async.TaskMetadata
- func (sc *Server) Metrics() metrics.Interface
- func (sc *Server) RemoteAddr() net.Addr
- func (sc *Server) Send(t serverutil.TaskCode, r io.Reader, f CallbackFunc) (async.TaskID, log.Interface, error)
- func (sc *Server) SetLogger(l log.Interface)
- func (sc *Server) SetMetrics(m metrics.Interface)
- func (sc *Server) TaskCodes() []serverutil.TaskCode
- func (sc *Server) Tasks() []async.TaskID
- func (sc *Server) Timestamp() time.Time
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 ¶
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) Close ¶
Close immediately closes the underlying connection to the server, and then blocks until all remaining callback functions have been called.
func (*Server) Disconnect ¶
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) 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) RemoteAddr ¶
RemoteAddr returns the remote network address.
func (*Server) Send ¶
func (sc *Server) Send(t serverutil.TaskCode, r io.Reader, f CallbackFunc) (async.TaskID, log.Interface, error)
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) SetMetrics ¶
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.