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
|
2014-01-16 15:16:35 +01:00
|
|
|
|
:meth:`sender()` method.
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
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
|
2013-01-22 15:24:15 -05:00
|
|
|
|
configured to support networking functions. These actor references will not
|
|
|
|
|
|
function if sent across a network connection to a remote JVM.
|
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
|
2013-01-22 15:24:15 -05:00
|
|
|
|
actors within the same JVM. In order to also be reachable when sent to
|
2012-01-18 10:10:42 +01:00
|
|
|
|
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
|
2013-01-22 15:24:15 -05:00
|
|
|
|
transparently and send them to the remote 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:
|
|
|
|
|
|
|
2013-01-22 15:24:15 -05:00
|
|
|
|
- :class:`PromiseActorRef` is the special representation of a :meth:`Promise`
|
|
|
|
|
|
for the purpose of being completed by the response from an actor.
|
|
|
|
|
|
:meth:`akka.pattern.ask` creates this actor reference.
|
2012-01-18 10:10:42 +01:00
|
|
|
|
- :class:`DeadLetterActorRef` is the default implementation of the dead
|
2013-01-22 15:24:15 -05:00
|
|
|
|
letters service to which Akka routes all messages whose destinations
|
|
|
|
|
|
are shut down or non-existent.
|
|
|
|
|
|
- :class:`EmptyLocalActorRef` is what Akka returns when looking up a
|
|
|
|
|
|
non-existent local actor path: it is equivalent to a
|
|
|
|
|
|
:class:`DeadLetterActorRef`, but it retains its path so that Akka can send
|
|
|
|
|
|
it over the network and compare it to other existing actor references for
|
|
|
|
|
|
that path, some of which might have been obtained before the actor died.
|
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`.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2016-07-06 05:00:48 +09:00
|
|
|
|
the name “path” to refer to it, although actor hierarchy has some fundamental difference from file system hierarchy.
|
2011-11-22 15:15:57 +01:00
|
|
|
|
|
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.
|
|
|
|
|
|
|
2013-03-13 16:01:57 +01:00
|
|
|
|
What is the Difference Between Actor Reference and Path?
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
|
|
An actor reference designates a single actor and the life-cycle of the reference
|
2013-03-26 18:17:50 +01:00
|
|
|
|
matches that actor’s life-cycle; an actor path represents a name which may or
|
|
|
|
|
|
may not be inhabited by an actor and the path itself does not have a life-cycle,
|
|
|
|
|
|
it never becomes invalid. You can create an actor path without creating an actor,
|
|
|
|
|
|
but you cannot create an actor reference without creating corresponding actor.
|
2013-03-13 16:01:57 +01:00
|
|
|
|
|
|
|
|
|
|
You can create an actor, terminate it, and then create a new actor with the same
|
|
|
|
|
|
actor path. The newly created actor is a new incarnation of the actor. It is not
|
|
|
|
|
|
the same actor. An actor reference to the old incarnation is not valid for the new
|
|
|
|
|
|
incarnation. Messages sent to the old actor reference will not be delivered
|
|
|
|
|
|
to the new incarnation even though they have the same path.
|
|
|
|
|
|
|
2011-12-22 16:44:50 +01:00
|
|
|
|
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::
|
|
|
|
|
|
|
2013-01-23 11:38:20 +01:00
|
|
|
|
"akka://my-sys/user/service-a/worker1" // purely local
|
|
|
|
|
|
"akka.tcp://my-sys@host.example.com:5678/user/service-b" // remote
|
|
|
|
|
|
|
2016-08-08 12:52:25 +02:00
|
|
|
|
Here, ``akka.tcp`` is the default remote transport for the 2.4 release; other transports
|
|
|
|
|
|
are pluggable.
|
2015-09-17 23:50:59 +09:00
|
|
|
|
The interpretation of the host and port part (i.e. ``host.example.com:5678`` in the example)
|
2013-01-23 11:38:20 +01:00
|
|
|
|
depends on the transport mechanism 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
|
2013-02-18 13:30:12 +01:00
|
|
|
|
created on a different network host than its parent, i.e. within a different
|
2012-01-18 10:10:42 +01:00
|
|
|
|
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.
|
|
|
|
|
|
|
2016-07-06 05:00:48 +09:00
|
|
|
|
|
|
|
|
|
|
Actor path alias or symbolic link?
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
As in some real file-systems you might think of a “path alias” or “symbolic link” for an actor,
|
|
|
|
|
|
i.e. one actor may be reachable using more than one path.
|
|
|
|
|
|
However, you should note that actor hierarchy is different from file system hierarchy.
|
|
|
|
|
|
You cannot freely create actor paths like symbolic links to refer to arbitrary actors.
|
|
|
|
|
|
As described in the above logical and physical actor path sections,
|
|
|
|
|
|
an actor path must be either logical path which represents supervision hierarchy, or
|
|
|
|
|
|
physical path which represents actor deployment.
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
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
|
2013-03-26 18:17:50 +01:00
|
|
|
|
:meth:`ActorSystem.actorSelection` method. The selection can be used for
|
|
|
|
|
|
communicating with said actor and the actor corresponding to the selection
|
|
|
|
|
|
is looked up when delivering each message.
|
|
|
|
|
|
|
|
|
|
|
|
To acquire an :class:`ActorRef` that is bound to the life-cycle of a specific actor
|
|
|
|
|
|
you need to send a message, such as the built-in :class:`Identify` message, to the actor
|
2014-01-16 15:16:35 +01:00
|
|
|
|
and use the ``sender()`` reference of a reply from the actor.
|
2013-03-26 18:17:50 +01:00
|
|
|
|
|
2011-11-22 15:15:57 +01:00
|
|
|
|
Absolute vs. Relative Paths
|
|
|
|
|
|
```````````````````````````
|
2011-11-20 21:47:16 +01:00
|
|
|
|
|
2013-03-26 18:17:50 +01:00
|
|
|
|
In addition to :meth:`ActorSystem.actorSelection` there is also
|
|
|
|
|
|
:meth:`ActorContext.actorSelection`, which is available inside any actor as
|
|
|
|
|
|
``context.actorSelection``. This yields an actor selection much like its twin on
|
2012-01-18 10:10:42 +01:00
|
|
|
|
: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
|
|
|
|
|
2013-03-26 18:17:50 +01:00
|
|
|
|
context.actorSelection("../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
|
|
|
|
|
|
|
2013-03-26 18:17:50 +01:00
|
|
|
|
context.actorSelection("/user/serviceA") ! msg
|
2011-12-15 15:09:16 +01:00
|
|
|
|
|
|
|
|
|
|
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
|
2015-05-08 10:25:39 +02:00
|
|
|
|
obtained using `actorSelection`, a traversal of the supervision hierarchy is done in
|
2012-01-18 10:10:42 +01:00
|
|
|
|
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
|
|
|
|
|
2013-03-26 18:17:50 +01:00
|
|
|
|
.. _actorOf-vs-actorSelection:
|
2011-12-28 13:09:56 +01:00
|
|
|
|
|
2015-05-08 10:25:39 +02:00
|
|
|
|
Summary: ``actorOf`` vs. ``actorSelection``
|
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2011-12-28 13:09:56 +01:00
|
|
|
|
|
|
|
|
|
|
.. 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).
|
|
|
|
|
|
|
2013-03-26 18:17:50 +01:00
|
|
|
|
- ``actorSelection`` only ever looks up existing actors when messages are
|
|
|
|
|
|
delivered, i.e. does not create actors, or verify existence of actors
|
|
|
|
|
|
when the selection is created.
|
|
|
|
|
|
|
2013-03-13 16:01:57 +01:00
|
|
|
|
Actor Reference and Path Equality
|
|
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
Equality of ``ActorRef`` match the intention that an ``ActorRef`` corresponds to
|
|
|
|
|
|
the target actor incarnation. Two actor references are compared equal when they have
|
|
|
|
|
|
the same path and point to the same actor incarnation. A reference pointing to a
|
|
|
|
|
|
terminated actor does not compare equal to a reference pointing to another (re-created)
|
2013-03-26 18:17:50 +01:00
|
|
|
|
actor with the same path. Note that a restart of an actor caused by a failure still
|
|
|
|
|
|
means that it is the same actor incarnation, i.e. a restart is not visible for the
|
2013-03-13 16:01:57 +01:00
|
|
|
|
consumer of the ``ActorRef``.
|
|
|
|
|
|
|
|
|
|
|
|
If you need to keep track of actor references in a collection and do not care about
|
|
|
|
|
|
the exact actor incarnation you can use the ``ActorPath`` as key, because the identifier
|
|
|
|
|
|
of the target actor is not taken into account when comparing actor paths.
|
|
|
|
|
|
|
2012-05-16 13:43:00 +02:00
|
|
|
|
Reusing Actor Paths
|
|
|
|
|
|
-------------------
|
|
|
|
|
|
|
2013-03-13 16:01:57 +01:00
|
|
|
|
When an actor is terminated, its reference will point to the dead letter mailbox,
|
2012-05-16 13:43:00 +02:00
|
|
|
|
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
|
2015-05-08 10:25:39 +02:00
|
|
|
|
the set of all actors ever created available—this is not good practice:
|
|
|
|
|
|
messages sent with ``actorSelection`` to an actor which “died” suddenly start to work
|
2013-03-26 18:17:50 +01:00
|
|
|
|
again, but without any guarantee of ordering between this transition and any
|
2013-03-13 16:01:57 +01:00
|
|
|
|
other event, hence the new inhabitant of the path may receive messages which were destined for the
|
2012-05-16 13:43:00 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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`.
|
|
|
|
|
|
|