Documentation ¶
Overview ¶
Package command defines the request commands that SDS Services will accept. Besides the commands, this package also defines the HandleFunc.
The HandleFunc is the function that executes the command and then returns the result to the caller.
Index ¶
- func Reply(reply interface{}) (message.Reply, error)
- type HandleFunc
- type Handlers
- type Name
- func (command Name) Push(socket *zmq.Socket, request interface{}) error
- func (command Name) Request(socket *remote.ClientSocket, request interface{}, reply interface{}) error
- func (command Name) RequestRouter(socket *remote.ClientSocket, targetService *parameter.Service, ...) error
- func (command Name) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HandleFunc ¶
HandleFunc is the function type that manipulates the commands. It accepts at least message.Request and log.Logger then returns message.Reply.
Optionally the controller can pass the shared states in the additional parameters. The most use case for optional parameter is to pass the link to the Database.
type Handlers ¶
type Handlers map[Name]HandleFunc
Handlers Binding of Command to the Command Handler.
func (Handlers) Add ¶
func (c Handlers) Add(command Name, handler HandleFunc) Handlers
Add Adds the Binding of command to handler in the handlers
func (Handlers) CommandNames ¶
CommandNames is the list of command names without handlers
type Name ¶
type Name string
Name is the string It's included in the message.Request when another thread or user requests the SDS Service
func (Name) Push ¶
Push the command to the remote thread or service with the given request parameters via the socket.
The Push is equivalent of Request without waiting for the remote socket's response.
Example:
request_parameters := key_value.Empty(). Set("timestamp", 1) heartbeat := New("HEARTBEAT") // create a command // Send HEARTBEAT command to the socket. _ := heartbeat.Request(socket, request_parameters) server_timestamp, _ := reply_parameters.GetUint64("server_timestamp")
func (Name) Request ¶
func (command Name) Request(socket *remote.ClientSocket, request interface{}, reply interface{}) error
Request the command to the remote thread or service with the given request parameters via the socket.
The response of the remote service is assigned to the reply.
The reply should be passed by pointer.
Example:
request_parameters := key_value.Empty() var reply_parameters key_value.Empty() ping_command := New("PING") // create a command // Send PING command to the socket. _ := ping_command.Request(socket, request_parameters, &reply_parameters) pong, _ := reply_parameters.GetString("pong")
func (Name) RequestRouter ¶
func (command Name) RequestRouter(socket *remote.ClientSocket, targetService *parameter.Service, request interface{}, reply interface{}) error
RequestRouter sends the command to the remote thread or service that over the proxy. The socket parameter is the proxy/broker socket. The service type is the service name that will accept the requests and response the reply.
The reply parameter must be passed by pointer.
In SeascapeSDS terminology, we call the proxy/broker as Router.
Example:
var reply key_value.KeyValue request_parameters := key_value.Empty(). Set("gold", 123) set := New("SET") // create a command db_service := parameter.DB // Send SET command to the database via the authentication proxy. _ := set.RequestRouter(auth_socket, db_service, request_parameters, &reply_parameters)