How to get information
Actors are implemented as Julia Task
s running asynchronously and are represented by a messaging Link
to them or by a registered name.
about an actor
You can use an actor's link (or its registered name) to get information about it:
julia> using Actors
julia> import Actors: spawn
julia> myBehavior(lk, f, args...) = send(lk, f(args...))
myBehavior (generic function with 1 method)
julia> me = newLink()
Link{Channel{Any}}(Channel{Any}(32), 1, :local)
julia> myactor = spawn(myBehavior, me)
Link{Channel{Any}}(Channel{Any}(32), 1, :default)
julia> info(myactor)
Actor default
Behavior myBehavior
Pid 1, Thread 1
Task @0x000000010d944230
Ident x-d-ukih-hamub
info
gives you some information about your actor. The system will on each worker pid
identify an actor as a Julia Task
. In order make it better identifiable for a human, the task address is also given as a Proquint identifier:
julia> using Proquint
julia> quint2uint("x-d-ukih-hamub")
0x000000010d944230
julia> info(myactor).task
0x000000010d944230
If you register
an actor, you can use its registered name to get the information. Then info
will show also the actor's name:
julia> register(:myname, myactor)
true
julia> info(:myname)
Actor default
Behavior myBehavior
Pid 1, Thread 1
Task @0x000000010d944230
Ident x-d-ukih-hamub
Name myname
about an actor's task
There are two ways to get the Task
variable from an actor:
- you
spawn
it with ataskref
keyword argument or - you use
Actors.diag
.
julia> t = Ref(Actors.diag(myactor, :task))
Base.RefValue{Task}(Task (runnable) @0x000000010d944230)
julia> t[]
Task (runnable) @0x000000010d944230
Note: if an actor is on a worker process (pid
> 1), you cannot get access to its Task
. Instead you will get a string representation of it.
about a failed actor
If an actor fails, info
will return the failed Task
, which shows a clickable stack-trace in the REPL:
julia> send(myactor, :boom)
(:boom,)
julia> info(myactor)
Task (failed) @0x000000010d944230
MethodError: objects of type Symbol are not callable
Stacktrace:
[1] myBehavior(::Link{Channel{Any}}, ::Symbol)
....
julia> typeof(ans)
Task
We can get the same information from the Ref{Task}
-variable, we created earlier:
julia> t
Base.RefValue{Task}(Task (failed) @0x000000010d944230)
julia> t[]
Task (failed) @0x000000010d944230
MethodError: objects of type Symbol are not callable
Stacktrace:
[1] myBehavior(::Link{Channel{Any}}, ::Symbol)
....
If a monitored or supervised actor has failed, you can get the failed task by using Actors.diag
with the :err
argument from the monitor or supervisor.
about actor state
For diagnostic purposes it is possible to get access to an actor's state by using Actors.diag
. See also Diagnostics.
about an actor system
You can get further informations about registered or supervised actors:
function | brief description |
---|---|
whereis | Find out whether an actor name is registered, |
registered | Return all registered actors in the system, |
count_children | tell a supervisor to return a children count, |
which_children | tell a supervisor to return a list of its children. |