2011-12-15 23:48:35 +01:00
|
|
|
|
.. _addressing:
|
|
|
|
|
|
|
2011-11-20 21:47:16 +01:00
|
|
|
|
Actor References, Paths and Addresses
|
|
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
|
|
|
|
This chapter describes how actors are identified and located within a possibly
|
2011-12-15 15:09:16 +01:00
|
|
|
|
distributed actor system. It ties into the central idea that
|
|
|
|
|
|
:ref:`actor-systems` form intrinsic supervision hierarchies as well as that
|
|
|
|
|
|
communication between actors is transparent with respect to their placement
|
|
|
|
|
|
across multiple network nodes.
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-12-22 15:51:18 +01:00
|
|
|
|
.. image:: ActorPath.png
|
|
|
|
|
|
|
|
|
|
|
|
The above image displays the relationship between the most important entities
|
|
|
|
|
|
within an actor system, please read on for the details.
|
|
|
|
|
|
|
2011-11-20 21:47:16 +01:00
|
|
|
|
What is an Actor Reference?
|
|
|
|
|
|
---------------------------
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
An actor reference is a subtype of :class:`ActorRef`, whose foremost purpose is
|
|
|
|
|
|
to support sending messages to the actor it represents. Each actor has access
|
|
|
|
|
|
to its canonical (local) reference through the :meth:`self` field; this
|
|
|
|
|
|
reference is also included as sender reference by default for all messages sent
|
|
|
|
|
|
to other actors. Conversely, during message processing the actor has access to
|
|
|
|
|
|
a reference representing the sender of the current message through the
|
2011-11-20 21:47:16 +01:00
|
|
|
|
:meth:`sender` field.
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
There are several different types of actor references that are supported
|
2011-11-20 21:47:16 +01:00
|
|
|
|
depending on the configuration of the actor system:
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- Purely local actor references are used by actor systems which are not
|
|
|
|
|
|
configured to support networking functions. These actor references cannot
|
2011-11-20 21:47:16 +01:00
|
|
|
|
ever be sent across a network connection while retaining their functionality.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- Local actor references when remoting is enabled are used by actor systems
|
|
|
|
|
|
which support networking functions for those references which represent
|
|
|
|
|
|
actors within the same JVM. In order to be recognizable also when sent to
|
|
|
|
|
|
other network nodes, these references include protocol and remote addressing
|
2011-11-20 21:47:16 +01:00
|
|
|
|
information.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- There is a subtype of local actor references which is used for routers (i.e.
|
|
|
|
|
|
actors mixing in the :class:`Router` trait). Its logical structure is the
|
|
|
|
|
|
same as for the aforementioned local references, but sending a message to
|
2011-12-02 09:34:19 +01:00
|
|
|
|
them dispatches to one of their children directly instead.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- Remote actor references represent actors which are reachable using remote
|
|
|
|
|
|
communication, i.e. sending messages to them will serialize the messages
|
2011-11-20 21:47:16 +01:00
|
|
|
|
transparently and send them to the other JVM.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- There are several special types of actor references which behave like local
|
2011-11-22 15:15:57 +01:00
|
|
|
|
actor references for all practical purposes:
|
|
|
|
|
|
|
2012-01-23 17:56:52 +01:00
|
|
|
|
- :class:`PromiseActorRef` is the special representation of a :meth:`Promise` for
|
2012-01-18 10:10:42 +01:00
|
|
|
|
the purpose of being completed by the response from an actor; it is created
|
2011-11-22 15:15:57 +01:00
|
|
|
|
by the :meth:`ActorRef.ask` invocation.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- :class:`DeadLetterActorRef` is the default implementation of the dead
|
2011-12-17 16:33:29 +01:00
|
|
|
|
letters service, where all messages are re-routed whose routees are shut
|
2011-11-22 15:15:57 +01:00
|
|
|
|
down or non-existent.
|
2012-01-23 17:56:52 +01:00
|
|
|
|
- :class:`EmptyLocalActorRef` is what is returned when looking up a
|
|
|
|
|
|
non-existing local actor path: it is equivalent to a
|
|
|
|
|
|
:class:`DeadLetterActorRef`, but it retains its path so that it can be sent
|
|
|
|
|
|
over the network and compared to other existing actor refs for that path,
|
|
|
|
|
|
some of which might have been obtained before the actor stopped existing.
|
2011-11-22 15:15:57 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- And then there are some one-off internal implementations which you should
|
2011-11-22 15:15:57 +01:00
|
|
|
|
never really see:
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- There is an actor reference which does not represent an actor but acts only
|
|
|
|
|
|
as a pseudo-supervisor for the root guardian, we call it “the one who walks
|
2011-11-22 15:15:57 +01:00
|
|
|
|
the bubbles of space-time”.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- The first logging service started before actually firing up actor creation
|
|
|
|
|
|
facilities is a fake actor reference which accepts log events and prints
|
2011-11-22 15:15:57 +01:00
|
|
|
|
them directly to standard output; it is :class:`Logging.StandardOutLogger`.
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- **(Future Extension)** Cluster actor references represent clustered actor
|
|
|
|
|
|
services which may be replicated, migrated or load-balanced across multiple
|
|
|
|
|
|
cluster nodes. As such they are virtual names which the cluster service
|
2011-11-20 21:47:16 +01:00
|
|
|
|
translates into local or remote actor references as appropriate.
|
2011-11-22 15:15:57 +01:00
|
|
|
|
|
|
|
|
|
|
What is an Actor Path?
|
|
|
|
|
|
----------------------
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
Since actors are created in a strictly hierarchical fashion, there exists a
|
|
|
|
|
|
unique sequence of actor names given by recursively following the supervision
|
|
|
|
|
|
links between child and parent down towards the root of the actor system. This
|
|
|
|
|
|
sequence can be seen as enclosing folders in a file system, hence we adopted
|
|
|
|
|
|
the name “path” to refer to it. As in some real file-systems there also are
|
|
|
|
|
|
“symbolic links”, i.e. one actor may be reachable using more than one path,
|
|
|
|
|
|
where all but one involve some translation which decouples part of the path
|
|
|
|
|
|
from the actor’s actual supervision ancestor line; these specialities are
|
2011-11-22 15:15:57 +01:00
|
|
|
|
described in the sub-sections to follow.
|
|
|
|
|
|
|
2011-12-22 16:44:50 +01:00
|
|
|
|
An actor path consists of an anchor, which identifies the actor system,
|
|
|
|
|
|
followed by the concatenation of the path elements, from root guardian to the
|
|
|
|
|
|
designated actor; the path elements are the names of the traversed actors and
|
|
|
|
|
|
are separated by slashes.
|
|
|
|
|
|
|
|
|
|
|
|
Actor Path Anchors
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
Each actor path has an address component, describing the protocol and location
|
|
|
|
|
|
by which the corresponding actor is reachable, followed by the names of the
|
2011-11-22 15:15:57 +01:00
|
|
|
|
actors in the hierarchy from the root up. Examples are::
|
|
|
|
|
|
|
2012-09-26 10:56:25 +02:00
|
|
|
|
"akka://my-sys/user/service-a/worker1" // purely local
|
|
|
|
|
|
"akka://my-sys@host.example.com:5678/user/service-b" // local or remote
|
|
|
|
|
|
"cluster://my-cluster/service-c" // clustered (Future Extension)
|
2011-11-22 15:15:57 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
Here, ``akka`` is the default remote protocol for the 2.0 release, and others
|
|
|
|
|
|
are pluggable. The interpretation of the host & port part (i.e.
|
|
|
|
|
|
``serv.example.com:5678`` in the example) depends on the transport mechanism
|
2011-12-15 15:09:16 +01:00
|
|
|
|
used, but it must abide by the URI structural rules.
|
2011-11-22 15:15:57 +01:00
|
|
|
|
|
|
|
|
|
|
Logical Actor Paths
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
The unique path obtained by following the parental supervision links towards
|
|
|
|
|
|
the root guardian is called the logical actor path. This path matches exactly
|
|
|
|
|
|
the creation ancestry of an actor, so it is completely deterministic as soon as
|
|
|
|
|
|
the actor system’s remoting configuration (and with it the address component of
|
2011-11-22 15:15:57 +01:00
|
|
|
|
the path) is set.
|
|
|
|
|
|
|
|
|
|
|
|
Physical Actor Paths
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
While the logical actor path describes the functional location within one actor
|
|
|
|
|
|
system, configuration-based remote deployment means that an actor may be
|
|
|
|
|
|
created on a different network host as its parent, i.e. within a different
|
|
|
|
|
|
actor system. In this case, following the actor path from the root guardian up
|
|
|
|
|
|
entails traversing the network, which is a costly operation. Therefore, each
|
|
|
|
|
|
actor also has a physical path, starting at the root guardian of the actor
|
|
|
|
|
|
system where the actual actor object resides. Using this path as sender
|
|
|
|
|
|
reference when querying other actors will let them reply directly to this
|
2011-11-22 15:15:57 +01:00
|
|
|
|
actor, minimizing delays incurred by routing.
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
One important aspect is that a physical actor path never spans multiple actor
|
|
|
|
|
|
systems or JVMs. This means that the logical path (supervision hierarchy) and
|
|
|
|
|
|
the physical path (actor deployment) of an actor may diverge if one of its
|
2011-11-22 15:15:57 +01:00
|
|
|
|
ancestors is remotely supervised.
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Actor Paths **(Future Extension)**
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
In order to be able to replicate and migrate actors across a cluster of Akka
|
|
|
|
|
|
nodes, another level of indirection has to be introduced. The cluster component
|
|
|
|
|
|
therefore provides a translation from virtual paths to physical paths which may
|
2011-11-22 15:15:57 +01:00
|
|
|
|
change in reaction to node failures, cluster rebalancing, etc.
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
*This area is still under active development, expect updates in this section
|
2011-11-22 15:15:57 +01:00
|
|
|
|
for the 2.1 release.*
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
|
|
|
|
|
How are Actor References obtained?
|
|
|
|
|
|
----------------------------------
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
There are two general categories to how actor references may be obtained: by
|
|
|
|
|
|
creating actors or by looking them up, where the latter functionality comes in
|
|
|
|
|
|
the two flavours of creating actor references from concrete actor paths and
|
2011-11-22 15:15:57 +01:00
|
|
|
|
querying the logical actor hierarchy.
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
*While local and remote actor references and their paths work in the same way
|
|
|
|
|
|
concerning the facilities mentioned below, the exact semantics of clustered
|
|
|
|
|
|
actor references and their paths—while certainly as similar as possible—may
|
|
|
|
|
|
differ in certain aspects, owing to the virtual nature of those paths. Expect
|
2011-11-22 15:15:57 +01:00
|
|
|
|
updates for the 2.1 release.*
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
Creating Actors
|
|
|
|
|
|
^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
2012-09-19 00:17:54 +02:00
|
|
|
|
An actor system is typically started by creating actors beneath the guardian
|
2012-01-18 10:10:42 +01:00
|
|
|
|
actor using the :meth:`ActorSystem.actorOf` method and then using
|
|
|
|
|
|
:meth:`ActorContext.actorOf` from within the created actors to spawn the actor
|
|
|
|
|
|
tree. These methods return a reference to the newly created actor. Each actor
|
2012-09-19 00:20:12 +02:00
|
|
|
|
has direct access (through its ``ActorContext``) to references for its parent,
|
|
|
|
|
|
itself and its children. These references may be sent within messages to other actors,
|
|
|
|
|
|
enabling those to reply directly.
|
2011-11-22 15:15:57 +01:00
|
|
|
|
|
|
|
|
|
|
Looking up Actors by Concrete Path
|
2011-11-20 21:47:16 +01:00
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
2011-12-15 15:09:16 +01:00
|
|
|
|
In addition, actor references may be looked up using the
|
|
|
|
|
|
:meth:`ActorSystem.actorFor` method, which returns an (unverified) local,
|
|
|
|
|
|
remote or clustered actor reference. Sending messages to such a reference or
|
2011-12-30 18:51:07 +01:00
|
|
|
|
attempting to observe its liveness will traverse the actor hierarchy of the
|
2011-12-15 15:09:16 +01:00
|
|
|
|
actor system from top to bottom by passing messages from parent to child until
|
|
|
|
|
|
either the target is reached or failure is certain, i.e. a name in the path
|
|
|
|
|
|
does not exist (in practice this process will be optimized using caches, but it
|
|
|
|
|
|
still has added cost compared to using the physical actor path, which can for
|
2012-08-21 09:04:24 +02:00
|
|
|
|
example be obtained from the sender reference included in replies from that
|
2011-12-15 15:09:16 +01:00
|
|
|
|
actor). The messages passed are handled automatically by Akka, so this process
|
|
|
|
|
|
is not visible to client code.
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
Absolute vs. Relative Paths
|
|
|
|
|
|
```````````````````````````
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
In addition to :meth:`ActorSystem.actorFor` there is also
|
|
|
|
|
|
:meth:`ActorContext.actorFor`, which is available inside any actor as
|
|
|
|
|
|
``context.actorFor``. This yields an actor reference much like its twin on
|
|
|
|
|
|
:class:`ActorSystem`, but instead of looking up the path starting from the root
|
|
|
|
|
|
of the actor tree it starts out on the current actor. Path elements consisting
|
|
|
|
|
|
of two dots (``".."``) may be used to access the parent actor. You can for
|
2011-11-22 15:15:57 +01:00
|
|
|
|
example send a message to a specific sibling::
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
context.actorFor("../brother") ! msg
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-12-15 15:09:16 +01:00
|
|
|
|
Absolute paths may of course also be looked up on `context` in the usual way, i.e.
|
|
|
|
|
|
|
|
|
|
|
|
.. code-block:: scala
|
|
|
|
|
|
|
|
|
|
|
|
context.actorFor("/user/serviceA") ! msg
|
|
|
|
|
|
|
|
|
|
|
|
will work as expected.
|
|
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
Querying the Logical Actor Hierarchy
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
Since the actor system forms a file-system like hierarchy, matching on paths is
|
2012-09-18 12:26:55 +02:00
|
|
|
|
possible in the same way as supported by Unix shells: you may replace (parts
|
2012-01-18 10:10:42 +01:00
|
|
|
|
of) path element names with wildcards (`«*»` and `«?»`) to formulate a
|
|
|
|
|
|
selection which may match zero or more actual actors. Because the result is not
|
|
|
|
|
|
a single actor reference, it has a different type :class:`ActorSelection` and
|
|
|
|
|
|
does not support the full set of operations an :class:`ActorRef` does.
|
|
|
|
|
|
Selections may be formulated using the :meth:`ActorSystem.actorSelection` and
|
2011-11-22 15:15:57 +01:00
|
|
|
|
:meth:`ActorContext.actorSelection` methods and do support sending messages::
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
context.actorSelection("../*") ! msg
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
will send `msg` to all siblings including the current actor. As for references
|
|
|
|
|
|
obtained using `actorFor`, a traversal of the supervision hierarchy is done in
|
|
|
|
|
|
order to perform the message send. As the exact set of actors which match a
|
|
|
|
|
|
selection may change even while a message is making its way to the recipients,
|
|
|
|
|
|
it is not possible to watch a selection for liveliness changes. In order to do
|
|
|
|
|
|
that, resolve the uncertainty by sending a request and gathering all answers,
|
|
|
|
|
|
extracting the sender references, and then watch all discovered concrete
|
|
|
|
|
|
actors. This scheme of resolving a selection may be improved upon in a future
|
2011-11-22 15:15:57 +01:00
|
|
|
|
release.
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-12-28 13:09:56 +01:00
|
|
|
|
.. _actorOf-vs-actorFor:
|
|
|
|
|
|
|
|
|
|
|
|
Summary: ``actorOf`` vs. ``actorFor``
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
|
|
What the above sections described in some detail can be summarized and
|
|
|
|
|
|
memorized easily as follows:
|
|
|
|
|
|
|
|
|
|
|
|
- ``actorOf`` only ever creates a new actor, and it creates it as a direct
|
|
|
|
|
|
child of the context on which this method is invoked (which may be any
|
|
|
|
|
|
actor or actor system).
|
|
|
|
|
|
|
|
|
|
|
|
- ``actorFor`` only ever looks up an existing actor, i.e. does not create
|
|
|
|
|
|
one.
|
|
|
|
|
|
|
2012-05-16 13:43:00 +02:00
|
|
|
|
Reusing Actor Paths
|
|
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
|
|
|
|
When an actor is terminated, its path will point to the dead letter mailbox,
|
|
|
|
|
|
DeathWatch will publish its final transition and in general it is not expected
|
|
|
|
|
|
to come back to life again (since the actor life cycle does not allow this).
|
|
|
|
|
|
While it is possible to create an actor at a later time with an identical
|
|
|
|
|
|
path—simply due to it being impossible to enforce the opposite without keeping
|
|
|
|
|
|
the set of all actors ever created available—this is not good practice: remote
|
|
|
|
|
|
actor references which “died” suddenly start to work again, but without any
|
|
|
|
|
|
guarantee of ordering between this transition and any other event, hence the
|
|
|
|
|
|
new inhabitant of the path may receive messages which were destined for the
|
|
|
|
|
|
previous tenant.
|
|
|
|
|
|
|
|
|
|
|
|
It may be the right thing to do in very specific circumstances, but make sure
|
|
|
|
|
|
to confine the handling of this precisely to the actor’s supervisor, because
|
|
|
|
|
|
that is the only actor which can reliably detect proper deregistration of the
|
|
|
|
|
|
name, before which creation of the new child will fail.
|
|
|
|
|
|
|
|
|
|
|
|
It may also be required during testing, when the test subject depends on being
|
|
|
|
|
|
instantiated at a specific path. In that case it is best to mock its supervisor
|
|
|
|
|
|
so that it will forward the Terminated message to the appropriate point in the
|
|
|
|
|
|
test procedure, enabling the latter to await proper deregistration of the name.
|
|
|
|
|
|
|
2011-11-20 21:47:16 +01:00
|
|
|
|
The Interplay with Remote Deployment
|
|
|
|
|
|
------------------------------------
|
|
|
|
|
|
|
2011-12-22 16:44:50 +01:00
|
|
|
|
When an actor creates a child, the actor system’s deployer will decide whether
|
|
|
|
|
|
the new actor resides in the same JVM or on another node. In the second case,
|
|
|
|
|
|
creation of the actor will be triggered via a network connection to happen in a
|
|
|
|
|
|
different JVM and consequently within a different actor system. The remote
|
|
|
|
|
|
system will place the new actor below a special path reserved for this purpose
|
|
|
|
|
|
and the supervisor of the new actor will be a remote actor reference
|
|
|
|
|
|
(representing that actor which triggered its creation). In this case,
|
|
|
|
|
|
:meth:`context.parent` (the supervisor reference) and
|
|
|
|
|
|
:meth:`context.path.parent` (the parent node in the actor’s path) do not
|
|
|
|
|
|
represent the same actor. However, looking up the child’s name within the
|
|
|
|
|
|
supervisor will find it on the remote node, preserving logical structure e.g.
|
|
|
|
|
|
when sending to an unresolved actor reference.
|
|
|
|
|
|
|
|
|
|
|
|
.. image:: RemoteDeployment.png
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
The Interplay with Clustering **(Future Extension)**
|
|
|
|
|
|
----------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
*This section is subject to change!*
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
When creating a scaled-out actor subtree, a cluster name is created for a
|
|
|
|
|
|
routed actor reference, where sending to this reference will send to one (or
|
|
|
|
|
|
more) of the actual actors created in the cluster. In order for those actors to
|
|
|
|
|
|
be able to query other actors while processing their messages, their sender
|
|
|
|
|
|
reference must be unique for each of the replicas, which means that physical
|
|
|
|
|
|
paths will be used as ``self`` references for these instances. In the case
|
|
|
|
|
|
of replication for achieving fault-tolerance the opposite is required: the
|
|
|
|
|
|
``self`` reference will be a virtual (cluster) path so that in case of
|
2011-11-22 15:15:57 +01:00
|
|
|
|
migration or fail-over communication is resumed with the fresh instance.
|
|
|
|
|
|
|
2011-11-20 21:47:16 +01:00
|
|
|
|
What is the Address part used for?
|
|
|
|
|
|
----------------------------------
|
|
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
When sending an actor reference across the network, it is represented by its
|
|
|
|
|
|
path. Hence, the path must fully encode all information necessary to send
|
|
|
|
|
|
messages to the underlying actor. This is achieved by encoding protocol, host
|
|
|
|
|
|
and port in the address part of the path string. When an actor system receives
|
|
|
|
|
|
an actor path from a remote node, it checks whether that path’s address matches
|
|
|
|
|
|
the address of this actor system, in which case it will be resolved to the
|
|
|
|
|
|
actor’s local reference. Otherwise, it will be represented by a remote actor
|
2011-11-20 21:47:16 +01:00
|
|
|
|
reference.
|
|
|
|
|
|
|
2012-08-14 20:42:54 +02:00
|
|
|
|
.. _toplevel-paths:
|
|
|
|
|
|
|
|
|
|
|
|
Top-Level Scopes for Actor Paths
|
|
|
|
|
|
--------------------------------
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
At the root of the path hierarchy resides the root guardian above which all
|
2012-08-14 20:42:54 +02:00
|
|
|
|
other actors are found; its name is ``"/"``. The next level consists of the
|
|
|
|
|
|
following:
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- ``"/user"`` is the guardian actor for all user-created top-level actors;
|
2012-08-14 20:42:54 +02:00
|
|
|
|
actors created using :meth:`ActorSystem.actorOf` are found below this one.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- ``"/system"`` is the guardian actor for all system-created top-level actors,
|
|
|
|
|
|
e.g. logging listeners or actors automatically deployed by configuration at
|
2011-11-20 21:47:16 +01:00
|
|
|
|
the start of the actor system.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- ``"/deadLetters"`` is the dead letter actor, which is where all messages sent to
|
2012-08-14 20:42:54 +02:00
|
|
|
|
stopped or non-existing actors are re-routed (on a best-effort basis: messages
|
|
|
|
|
|
may be lost even within the local JVM).
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- ``"/temp"`` is the guardian for all short-lived system-created actors, e.g.
|
2011-11-20 21:47:16 +01:00
|
|
|
|
those which are used in the implementation of :meth:`ActorRef.ask`.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- ``"/remote"`` is an artificial path below which all actors reside whose
|
2011-11-20 21:47:16 +01:00
|
|
|
|
supervisors are remote actor references
|
2011-12-15 15:09:16 +01:00
|
|
|
|
|
2012-08-14 20:42:54 +02:00
|
|
|
|
The need to structure the name space for actors like this arises from a central
|
|
|
|
|
|
and very simple design goal: everything in the hierarchy is an actor, and all
|
|
|
|
|
|
actors function in the same way. Hence you can not only look up the actors you
|
|
|
|
|
|
created, you can also look up the system guardian and send it a message (which
|
|
|
|
|
|
it will dutifully discard in this case). This powerful principle means that
|
|
|
|
|
|
there are no quirks to remember, it makes the whole system more uniform and
|
|
|
|
|
|
consistent.
|
|
|
|
|
|
|
|
|
|
|
|
If you want to read more about the top-level structure of an actor system, have
|
|
|
|
|
|
a look at :ref:`toplevel-supervisors`.
|
|
|
|
|
|
|