The actor path

In accordance with the actor model, Akka actors are hierarchical.

The actor path is built by taking the names of each actor in the hierarchy up to the root actor and concatenating them right-to-left using slashes. In the beginning of the path, there is an address part identifying the protocol and location of the actor system. This address part is called the anchor and its representation is different for local and remote systems.

In our example, the whole path for the Boy which is described by the local path /Manager/Boy in the deployment configuration will be akka://user/Bakery/Manager/Boy (purely local path) for the Boy actor and an akka.tcp://[email protected]:2553/user/Seller (remote path) for the Seller actor in the remote Store actor system, as shown from the Bakery side.

As you can see, remoting introduces the necessary differences in the way the actor path is built and used. 

The main purpose of the actor path is to address an actor we are about to send messages to. On a technical level, we have an abstraction for sending messages to an actor, which is ActorRefFor each actor, its ActorRef provides access to its local reference through the self field and to the sender of the current message via the context.sender(). Each ActorRef references exactly one actor. ActorRef also incorporates a dispatcher and a mailbox for the actor. The dispatcher is responsible for queueing messages in the actor's mailbox and dequeueing them at a certain time before passing them to the actors' receive method.

We've already seen both ways to create an ActorRef:

  1. By creating an actor using context.actorOf
  2. By looking up one or multiple actors using context.actorSelection

There are different ways to provide an actor path for the lookup in the second case:

  • Absolute pathcontext.actorSelection("/user/Manager/Boy") returns a single actor with a path specified or empty selection
  • Relative pathcontext.actorSelection("../sibling") goes up to the parent in the hierarchy and then down to the "sibling" in the case that it exists.
  • Wildcards: context.actorSelection("../*") goes up in the hierarchy and selects all of the children of the actor's parent, including the current actor
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.15.154