Documentation
¶
Index ¶
- func MachineId() string
- func RegisterType(message Message)
- func Run()
- type Abortable
- type Actor
- type Context
- func (c *Context) Defer(action func())
- func (c *Context) Kill(pid *Pid)
- func (c *Context) Monitor(pid *Pid) Abortable
- func (c *Context) MonitorMachine(machine *Machine) Abortable
- func (c *Context) PassthroughPoisonPill(val bool)
- func (c *Context) Quit()
- func (c *Context) Self() *Pid
- func (c *Context) Send(to *Pid, message Message)
- func (c *Context) SendAfter(to *Pid, message Message, duration time.Duration) Abortable
- func (c *Context) Span() opentracing.Span
- func (c *Context) Trace(name string)
- func (c *Context) TraceFork(traceFork func(ctx opentracing.SpanContext) opentracing.SpanReference)
- type DisconnectMessage
- type DownMessage
- type EmptyMessage
- type GenericMessage
- type KillMessage
- type Machine
- type Message
- type Pid
- type PoisonPill
- type RemoteSystem
- type StatelessActor
- type System
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterType ¶
func RegisterType(message Message)
RegisterType registers a Message to the type store so it can be sent to remote machines (which, of course, need a Message with the same Message.Type registered).
Types ¶
type Abortable ¶
type Abortable interface {
//The Abort function aborts the underlying task (e.g. a Monitor) when called.
Abort()
}
The Abortable interface defines the methods a struct has to implement so it can be returned by an action that can be canceled. It is very similar to context.Context with the key difference that an Abortable can only Abort and doesn't carry any further details about the underlying action.
type Actor ¶
type Actor interface { //Init is called when an Actor is initialized. It is //guaranteed to be called before an Actor has been registered //or even started. Typically, Init is used to start monitors //to other actors or do some setup work. The caller //function provides a Context to the Init function. //Context can be used to interact with other actors //(e.g. send, monitor, etc) or modify the current Actor //(e.g. quit, defer actions, etc). Init(ctx *Context) //Run is called when an Actor receives a Message. The caller //function provides both a Context as well as the actual //Message to the Run function. Context can then be used to //interact with other actors (e.g. send, monitor, etc) or //modify the current Actor (e.g. quit, defer actions, etc). Run(ctx *Context, message Message) }
The Actor interface defines the methods a struct has to implement so it can be spawned by quacktors.
type Context ¶
type Context struct { Logger contextLogger // contains filtered or unexported fields }
The Context struct defines the actor context and provides ways for an actor to interact with the rest of the system. Actors are provided a Context instance on Init and Run. Actors should only use the provided context to interact with other actors as the Context also stores things like current Span or a pointer to the acto specific send mutex.
func RootContext ¶
func RootContext() Context
RootContext returns a context that can be used outside an Actor. It is not associated with a real PID and therefore, one should not call anything with the RootContext that requires it to be able to receive or the like (e.g. no Context.Quit, Context.Monitor, etc.).
func RootContextWithSpan ¶ added in v0.0.5
func RootContextWithSpan(span opentracing.Span) Context
RootContextWithSpan is the same as RootContext but with a tracing span attached to it so it will do distributed tracing.
func VectorContext ¶ added in v0.0.5
VectorContext creates a context with a custom name and opentracing.Span. This allows for integrating applications with quacktors.
func (*Context) Defer ¶
func (c *Context) Defer(action func())
Defer defers an action to after an actor has gone down. The same general advice applies to the Defer function as to the built-in Go defer (e.g. avoid defers in for loops, no nil function defers, etc). Deferred actor functions should not panic (because nothing will happen if they do, quacktors just recovers the panic).
func (*Context) Monitor ¶
Monitor starts a monitor on another actor. As soon as the actor goes down, a DownMessage is sent to the monitoring actor. Monitor also returns an Abortable so the monitor can be canceled (i.e. no DownMessage will be sent out if the monitored actor goes down).
func (*Context) MonitorMachine ¶
MonitorMachine starts a monitor on a connection to a remote machine. As soon as the remote disconnects, a DisconnectMessage is sent to the monitoring actor. MonitorMachine also returns an Abortable so the monitor can be canceled (i.e. no DisconnectMessage will be sent out if the monitored actor goes down).
func (*Context) PassthroughPoisonPill ¶ added in v0.0.6
PassthroughPoisonPill enables message passthrough for PoisonPill messages. If set to true, PoisonPill messages will not shut down the actor but be forwarded to the handler function.
func (*Context) SendAfter ¶
SendAfter schedules a Message to be sent to another actor by its PID after a timer has finished. SendAfter also returns an Abortable so the scheduled Send can be stopped. If the sending actor goes down before the timer has completed, the Send operation is still executed.
func (*Context) Span ¶ added in v0.0.5
func (c *Context) Span() opentracing.Span
Span returns the current opentracing.Span. This will always be nil unless Trace was called with a service name in the Init function of the actor.
type DisconnectMessage ¶
type DisconnectMessage struct { //MachineId is the ID of the Machine that disconnected. MachineId string //Address is the remote address of the Machine. Address string }
The DisconnectMessage is sent to a monitoring Actor whenever a monitored Machine connection goes down.
func (DisconnectMessage) Type ¶
func (d DisconnectMessage) Type() string
Type of DisconnectMessage returns "DisconnectMessage"
type DownMessage ¶
type DownMessage struct { //Who is the PID of the Actor that went down. Who *Pid }
The DownMessage is sent to a monitoring Actor whenever a monitored Actor goes down.
func (DownMessage) Type ¶
func (d DownMessage) Type() string
Type of DownMessage returns "DownMessage"
type EmptyMessage ¶
type EmptyMessage struct { }
The EmptyMessage struct is an empty message without any semantic meaning (i.e. it literally doesn't do anything).
func (EmptyMessage) Type ¶
func (e EmptyMessage) Type() string
Type of EmptyMessage returns "EmptyMessage"
type GenericMessage ¶
type GenericMessage struct {
//Value is the value a GenericMessage carries.
Value interface{} `json:"value"`
}
The GenericMessage carries a single Value of type interface{}.
func (GenericMessage) Type ¶
func (g GenericMessage) Type() string
Type of GenericMessage returns "GenericMessage"
type KillMessage ¶
type KillMessage struct { }
A KillMessage can be sent to an Actor to ask it to shut down. It is entirely semantic, meaning this will not shut the Actor down automatically. Instead, the Actor should clean up whatever it is doing gracefully and then call Context.Quit itself.
func (KillMessage) Type ¶
func (k KillMessage) Type() string
Type of KillMessage returns "KillMessage"
type Machine ¶
type Machine struct { MachineId string Address string MessageGatewayPort uint16 GeneralPurposePort uint16 // contains filtered or unexported fields }
Machine is the struct representation of a remote machine.
type Message ¶
type Message interface { //Type returns the the "name" of the Message. //This is used to identify and correctly unmarshal //messages from remote actors. Type() string }
The Message interface defines all methods a struct has to implement so it can be sent around by actors.
type Pid ¶
The Pid struct acts as a reference to an Actor. It is completely location transparent, meaning it doesn't matter if the Pid is actually on another system. To the developer it will look like just another Actor they can send messages to.
func Spawn ¶
Spawn spawns an Actor from an anonymous receive function and returns the *Pid of the Actor.
func SpawnWithInit ¶
SpawnWithInit spawns an Actor from an anonymous receive function and an anonymous init function and returns the *Pid of the Actor.
type PoisonPill ¶
type PoisonPill struct { }
A PoisonPill can be sent to an Actor to kill it without aborting current (or already queued) messages. Instead, it is enqueued into the actors mailbox and when the Actor gets to the PoisonPill Message, gracefully shuts it down. A PoisonPill never gets passed on to the Run function. Instead, it just calls Context.Quit on the current actors Context.
type RemoteSystem ¶
RemoteSystem is the struct representation of a system (i.e. a collection of PIDs that have been assigned a name) on a remote machine.
func Connect ¶
func Connect(name string) (*RemoteSystem, error)
Connect connects to a remote system and returns a *RemoteSystem and an error (nil if everything went fine). The connection string format should be "system@remote" where "system" is the name of the remote system and "remote" is either an IP or a domain name.
type StatelessActor ¶
type StatelessActor struct { InitFunction func(ctx *Context) ReceiveFunction func(ctx *Context, message Message) }
The StatelessActor struct is the Actor implementation that is used when using Spawn or SpawnWithInit. As the name implies, the StatelessActor doesn't have a state and just requires one anonymous function as the initializer (for Init) and another one as the run function (for Run) to work. ReceiveFunction can be nil, InitFunction has to be set.
func (*StatelessActor) Init ¶
func (s *StatelessActor) Init(ctx *Context)
Init initializes the StatelessActor by calling InitFunction if it is not nil. Init panics if ReceiveFunction is not set.
func (*StatelessActor) Run ¶
func (s *StatelessActor) Run(ctx *Context, message Message)
Run forwards both the Message and the Context to the ReceiveFunction when the StatelessActor receives a message.
type System ¶
type System struct {
// contains filtered or unexported fields
}
The System struct represents a logical actor system (i.e. a collection of PIDs that have been assigned a handler name so that remote machines can look them up). Furthermore, the System struct also keeps track of the connection to the local qpmd and keeps track of the system server status (the server which is used to look up PIDs by handler names, etc).
func NewSystem ¶
NewSystem creates a new system server, connects to qpmd, starts the qpmd heartbeat for the new system and returns a *System and an error (nil if everything went fine).
func (*System) Close ¶
func (s *System) Close()
Close closes the connection to the local qpmd and quits the system server.
func (*System) HandleRemote ¶
HandleRemote associates a PID with a handler name.