Messages

Actors can be called, updated, queried … This is implemented with Julia's multiple dispatch. An actors dispatches the onmessage methods on the incoming messages:

ActorInterfaces.Classic.onmessageFunction
onmessage(bhv, msg)

Default behavior function to execute the current actor behavior bhv with the message msg. The actor calls bhv(msg) when a message arrives.

Parameters

  • bhv: excutable object (closure or functor) taking parameters msg,
  • msg: message parameters to bhv.
source
onmessage(A::_ACT, msg)
onmessage(A::_ACT, mode, msg)

An actor executes this function when a message arrives.

Actor libraries or applications can use this to

  • plugin the Actors.jl API (first form) or
  • extend it to other protocols by using the 2nd form.
source

Internal Messages

The actor's onmessage methods are dispatched by and do different things with the following internal messages:

Actors.CallType
Call(arg, from::Link)

A synchronous Msg to an actor to execute its behavior with arg... and to send the result as a Response message to from.

source
Actors.CastType
Cast(arg)

An asynchronous Msg to an actor to execute its behavior with arg... without sending a response.

If the actor is set to state dispatch, it updates its internal state with the result.

source
Actors.ConnectType
Connect(x, remove=false)

A Msg to an actor to connect with x. If remove=true, an existing connection gets removed.

source
Actors.DiagType
Diag(x, from::Link)

A synchronous Msg to an actor to send diagnostic information.

source
Actors.DownType
Down(from, reason, task)

A Msg to a monitor actor indicating that an error has occurred or a Exit has been received.

source
Actors.ExitType
Exit(reason, from, task, state)

A Msg to an actor causing it to terminate. Exit messages are sent to connected actors if an error has occurred and then are propagated further. They are not propagated by :sticky actors, see trapExit.

source
Actors.ExecType
Exec(func::Bhv, from::Link)

A synchronous Msg to an actor to execute func and to send a Response message with the return value to from.

source
Actors.QueryType
Query(s::Symbol, from::Link)

A Msg to an actor to send a Response message with one of its internal state variables s to from.

  • s::Symbol can be one of :sta, :res, :bhv, :dsp.
source
Actors.UpdateType
Update(s::Symbol, x)

An asynchronous Msg to an actor to update its internal state s to x.

  • s::Symbol can be one of :arg, :self, :sta, :usr.
source

User extensions

There are four ways to extend the messaging protocol and the functionality of Actors:

  1. If a user defines its own messages of type Msg and sends them to an actor, it passes them on as remaining argument to the behavior function.
  2. Alternatively a user can extend Actors.onmessage with his own methods to dispatch on those messages and doing user defined things.
  3. A user can set the actor mode with spawn or change it with update! to something other than :default, e.g. :mymode. If he then implements a method Actors.onmessage(A::_ACT, ::Val{:mymode}, msg::Call) and so on, the actor will dispatch that one when it receives a Call message.
  4. Finally a user can implement other message types and messaging protocols and extend Actors.onmessage for dispatching on those.