action

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package action implements the Cloudstate Action protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CancelFunc

type CancelFunc func(c *Context) error

type CloseFunc

type CloseFunc func(c *Context) error

type CommandID

type CommandID int64

type Context

type Context struct {
	// Entity describes the instance that is used as an entity.
	Entity *Entity
	// Instance is the instance of the entity this context is for.
	Instance EntityHandler
	// contains filtered or unexported fields
}

func (*Context) Cancel

func (c *Context) Cancel()

Cancel cancels server command streaming.

func (*Context) CancellationFunc

func (c *Context) CancellationFunc(cancel CancelFunc)

func (*Context) CloseFunc

func (c *Context) CloseFunc(close CloseFunc)

CloseFunc registers a function that is called whenever a client closes a stream.

func (*Context) Command

func (c *Context) Command() *entity.ActionCommand

func (*Context) Forward

func (c *Context) Forward(forward *protocol.Forward)

func (*Context) Metadata

func (c *Context) Metadata() *protocol.Metadata

func (*Context) Respond

func (c *Context) Respond(err error) error

func (*Context) RespondWith

func (c *Context) RespondWith(response *any.Any)

func (*Context) SideEffect

func (c *Context) SideEffect(effect *protocol.SideEffect)

type Entity

type Entity struct {
	// ServiceName is the fully qualified name of the service that implements
	// this entities interface. Setting it is mandatory.
	ServiceName ServiceName
	// EntityFunc creates a new entity.
	EntityFunc func() EntityHandler
}

type EntityHandler

type EntityHandler interface {
	HandleCommand(ctx *Context, name string, msg proto.Message) error
}

type EntityID

type EntityID string

type RespondFunc

type RespondFunc func(c *Context) error

type Server

type Server struct {

	// internal marker enforced by go-grpc.
	entity.UnimplementedActionProtocolServer
	// contains filtered or unexported fields
}

Server is the implementation of the Server server API for the CRDT service.

func NewServer

func NewServer() *Server

func (*Server) HandleStreamed

func (s *Server) HandleStreamed(stream entity.ActionProtocol_HandleStreamedServer) error

HandleStreamed handles a full duplex streamed command.

The first message in will contain the request metadata, including the service name and command name. It will not have an associated payload set. This will be followed by zero to many messages in with a payload, but no service name or command name set.

Zero or more replies may be sent, each containing either a direct reply, a forward or a failure, and each may contain many side effects.

If the underlying transport supports per stream metadata, rather than per message metadata, then that metadata will only be included in the metadata of the first message. In contrast, if the underlying transport supports per message metadata, there will be no metadata on the first message, the metadata will instead be found on each subsequent message.

The semantics of stream closure in this protocol map 1:1 with the semantics of gRPC stream closure, that is, when the client closes the stream, the stream is considered half closed, and the server should eventually, but not necessarily immediately, close the stream with a status code and trailers.

If however the server closes the stream with a status code and trailers, the stream is immediately considered completely closed, and no further messages sent by the client will be handled by the server.

Either the client or the server may cancel the stream at any time, cancellation is indicated through an HTTP2 stream RST message.

func (*Server) HandleStreamedIn

func (s *Server) HandleStreamedIn(stream entity.ActionProtocol_HandleStreamedInServer) error

HandleStreamedIn handles a streamed in command. The first message in will contain the request metadata, including the service name and command name. It will not have an associated payload set. This will be followed by zero to many messages in with a payload, but no service name or command name set.

If the underlying transport supports per stream metadata, rather than per message metadata, then that metadata will only be included in the metadata of the first message. In contrast, if the underlying transport supports per message metadata, there will be no metadata on the first message, the metadata will instead be found on each subsequent message.

The semantics of stream closure in this protocol map 1:1 with the semantics of gRPC stream closure, that is, when the client closes the stream, the stream is considered half closed, and the server should eventually, but not necessarily immediately, send a response message with a status code and trailers. If however the server sends a response message before the client closes the stream, the stream is completely closed, and the client should handle this and stop sending more messages.

Either the client or the server may cancel the stream at any time, cancellation is indicated through an HTTP2 stream RST message.

func (*Server) HandleStreamedOut

func (s *Server) HandleStreamedOut(command *entity.ActionCommand, stream entity.ActionProtocol_HandleStreamedOutServer) error

HandleStreamedOut handles a streamed out command. The input command will contain the service name, command name, request metadata and the command payload. Zero or more replies may be sent, each containing either a direct reply, a forward or a failure, and each may contain many side effects. The stream to the client will be closed when the this stream is closed, with the same status as this stream is closed with.

Either the client or the server may cancel the stream at any time, cancellation is indicated through an HTTP2 stream RST message.

func (*Server) HandleUnary

func (s *Server) HandleUnary(ctx context.Context, command *entity.ActionCommand) (*entity.ActionResponse, error)

HandleUnary handles an unary command. The input command will contain the service name, command name, request metadata and the command payload. The reply may contain a direct reply, a forward or a failure, and it may contain many side effects.

func (*Server) Register

func (s *Server) Register(e *Entity) error

type ServiceName

type ServiceName string

func (ServiceName) String

func (sn ServiceName) String() string

Jump to

Keyboard shortcuts

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