server

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: 13 Imported by: 1

Documentation

Index

Constants

View Source
const BACKEND_ROUTER_PATH string = "inproc://rpc_backend_router"
View Source
const OUTSTANDING_REQUESTS_PER_THREAD uint = 50

Variables

View Source
var MAGIC_READY_STRING []byte = []byte("___ReAdY___")
View Source
var MAGIC_STOP_STRING []byte = []byte("___STOPBALANCER___")

Functions

This section is empty.

Types

type Context

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

Opaque structure that contains request information and takes the response.

func (*Context) AppendCallTrace

func (c *Context) AppendCallTrace(traceinfo *proto.TraceInfo)

Append traceinfo from child call.

func (*Context) Fail

func (c *Context) Fail(msg string)

Fail with msg as error message (sent back to the client)

func (*Context) GetArgument

func (c *Context) GetArgument(msg pb.Message) error

GetArgument serializes the input (from GetInput()) in a protocol buffer message.

func (*Context) GetClientId

func (c *Context) GetClientId() string

GetClientId returns the identification that the client sent.

func (*Context) GetDeadline

func (c *Context) GetDeadline() time.Time

Get the absolute deadline requested by the caller.

func (*Context) GetDeadlineNotifier

func (c *Context) GetDeadlineNotifier() <-chan time.Time

Returns a channel that is sent a value when the deadline of this RPC has passed.

func (*Context) GetInput

func (c *Context) GetInput() []byte

Get the bytes sent by the client.

func (*Context) GetTraceInfo

func (c *Context) GetTraceInfo() *proto.TraceInfo

For half-external use, e.g. by the client package. Returns not nil when the current call tree is traced.

func (*Context) Return

func (c *Context) Return(msg pb.Message) error

Set Success flag and the message to return to the caller. Does not do anything special, such as terminate the calling function etc.

This is essentially Success(), but with implicit protobuf serialization.

func (*Context) Success

func (c *Context) Success(data []byte)

Set Success flag and the data to return to the caller.

type Handler

type Handler (func(*Context))

A function that is called when the corresponding endpoint is requested. Note that it makes sense to use a bound function: RegisterHandler("Service", "Method", server.method) wherein server is an object with associated function method().

type Server

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

Handles incoming requests and registering of handler functions.

func NewIPCServer

func NewIPCServer(path string, threads uint, security_manager *smgr.ServerSecurityManager) (*Server, error)

func NewServer

func NewServer(host string, port uint, threads uint, security_manager *smgr.ServerSecurityManager) (*Server, error)

Create server listening on the specified laddr:port. laddr has to be "*" or an IP address, names do not work. There is usually only one server listening per process (though it is possible to use multiple servers on different ports, of course)

worker_threads is the number of workers; however, there are (additionally) at least one load-balancing thread and one ZeroMQ networking thread.

security_manager adds CURVE and IP "authentication" security to the server. If it's nil, do not add security.

Use the setter functions described below before calling Start(), otherwise they might be ignored.

func (*Server) Close

func (srv *Server) Close()

Close internal sockets. The server may not be used after calling Close().

func (*Server) RegisterHandler

func (srv *Server) RegisterHandler(svc, endpoint string, handler Handler) (err error)

Add a new endpoint (i.e. a handler); svc is the "namespace" in which to register the handler, endpoint the name with which the handler can be identified from the outside. The service is created implicitly

err is not nil if the endpoint is already registered.

func (*Server) SetLameduck

func (srv *Server) SetLameduck(lameduck bool)

A server that is in lameduck mode will respond negatively to health checks but continue serving requests.

func (*Server) SetLoadshed

func (srv *Server) SetLoadshed(loadshed bool)

A server in loadshed mode will refuse any requests immediately.

func (*Server) SetMachineName

func (srv *Server) SetMachineName(name string)

Set the machine name as shown in traces (os.Hostname() can be used to obtain the DNS name)

func (*Server) SetRPCLogger

func (cl *Server) SetRPCLogger(l *golog.Logger)

Log all RPCs made by this client to this logging device; either as hex/raw strings or protobuf strings.

func (*Server) SetTimeout

func (srv *Server) SetTimeout(d time.Duration)

Set timeout for the routers used by the loadbalancer (the worker sockets don't really need a timeout because they're communicating via inproc://)

func (*Server) Start

func (srv *Server) Start() error

Starts worker threads. Returns an error if any thread couldn't set up its socket, otherwise it blocks until the server is stopped. The error is logged at any LOGLEVEL.

func (*Server) Stop

func (srv *Server) Stop() error

Connect to loadbalancer thread and send special stop message. Does not close sockets etc.

func (*Server) UnregisterHandler

func (srv *Server) UnregisterHandler(svc, endpoint string) (err error)

Removes an endpoint from the set of served endpoints.

Returns an error value with a description if the endpoint doesn't exist.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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