command

package
v0.0.0-...-fe5670a Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Reply

func Reply(reply interface{}) (message.Reply, error)

Reply creates a successful message.Reply with the given reply parameters.

Types

type HandleFunc

type HandleFunc = func(message.Request, log.Logger, remote.Clients) message.Reply

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 EmptyHandlers

func EmptyHandlers() Handlers

EmptyHandlers returns an empty 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

func (c Handlers) CommandNames() []string

CommandNames is the list of command names without handlers

func (Handlers) Exist

func (c Handlers) Exist(command Name) bool

Exist returns true if the handler function exists for the command.

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 New

func New(value string) Name

New Converts the given string to the CommandName

func (Name) Push

func (command Name) Push(socket *zmq.Socket, request interface{}) error

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)

func (Name) String

func (command Name) String() string

String representation of the CommandName

Jump to

Keyboard shortcuts

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