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.jl
API (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
— TypeActors.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
— TypeActors.Exit
— TypeActors.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::Symbol
can 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::Symbol
can 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
Msg
and sends them to an actor, it passes them on as remaining argument to the behavior function. - Alternatively a user can extend
Actors.onmessage
with his own methods to dispatch on those messages and doing user defined things. - A user can set the actor mode with
spawn
or 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 aCall
message. - Finally a user can implement other message types and messaging protocols and extend
Actors.onmessage
for dispatching on those.