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.onmessage — Functiononmessage(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 parametersmsg,msg: message parameters tobhv.
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.jlAPI (first form) or - extend it to other protocols by using the 2nd form.
Internal Messages
The actor's onmessage methods are dispatched by and do different things with the following internal messages:
Actors.Become — TypeBecome(bhv)An asynchronous Msg to an actor to change its behavior to bhv.
Actors.Call — TypeCall(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.
Actors.Cast — TypeCast(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.
Actors.Connect — TypeConnect(x, remove=false)A Msg to an actor to connect with x. If remove=true, an existing connection gets removed.
Actors.Diag — TypeDiag(x, from::Link)A synchronous Msg to an actor to send diagnostic information.
Actors.Down — TypeDown(from, reason, task)A Msg to a monitor actor indicating that an error has occurred or a Exit has been received.
Actors.Exit — TypeExit(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.
Actors.Exec — TypeExec(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.
Actors.Init — TypeActors.Query — TypeQuery(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::Symbolcan be one of:sta,:res,:bhv,:dsp.
Actors.Term — TypeActors.Timeout — TypeTimeout()A return value to signal that a timeout has occurred.
Actors.Update — TypeUpdate(s::Symbol, x)An asynchronous Msg to an actor to update its internal state s to x.
s::Symbolcan be one of:arg,:self,:sta,:usr.
User extensions
There are four ways to extend the messaging protocol and the functionality of Actors:
- If a user defines its own messages of type
Msgand sends them to an actor, it passes them on as remaining argument to the behavior function. - Alternatively a user can extend
Actors.onmessagewith his own methods to dispatch on those messages and doing user defined things. - A user can set the actor mode with
spawnor change it withupdate!to something other than:default, e.g.:mymode. If he then implements a methodActors.onmessage(A::_ACT, ::Val{:mymode}, msg::Call)and so on, the actor will dispatch that one when it receives aCallmessage. - Finally a user can implement other message types and messaging protocols and extend
Actors.onmessagefor dispatching on those.