concept ActorRef in category akka

This is an excerpt from Manning's book Akka in Action.
Messages are sent to the actor’s ActorRef. Every actor has a mailbox—it’s a lot like a queue. Messages sent to the ActorRef will be temporarily stored in the mailbox to be processed later, one at a time, in the order they arrived. Figure 1.21 shows the relationship between the ActorRef, the mailbox, and the actor.
We’ll load this configuration string into an ActorSystem. Most notably it defines a specific ActorRefProvider for remoting, which bootstraps the akka-remote module. As the name suggests, it also takes care of providing your code with ActorRefs to remote actors. The following listing first imports the required config and actor packages, and then loads the config into an actor system.
The frontend needs the new the backend configuration to be able to connect to the remote BoxOffice. Getting an ActorSelection to the remote actor was fine in the REPL console, just to try out sending a message, when we were certain that the backend was present. In this case we’d like to work with an ActorRef instead, since the single-node version used one. We create a new actor RemoteLookupProxy, which is responsible for the lookup of the remote BoxOffice and forwarding the messages. The FrontendMain object creates the RemoteLookupProxy actor to look up the BoxOffice actor.
Listing 6.10. Looking up the remote BoxOffice
def createPath(): String = { #1 val config = ConfigFactory.load("frontend").getConfig("backend") #2 val host = config.getString("host") val port = config.getInt("port") val protocol = config.getString("protocol") val systemName = config.getString("system") val actorName = config.getString("actor") s"$protocol://$systemName@$host:$port/$actorName" } def createBoxOffice: ActorRef = { val path = createPath() system.actorOf(Props(new RemoteLookupProxy(path)), "lookupBoxOffice") } #3 #1 - Creates path to BoxOffice #2 - Loads frontend.conf configuration and gets backend config section properties to build the path #3 - Returns an Actor that looks up box office actor. The Actor is constructed with one argument: the path to the remote BoxOffice. !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[]"} !@%STYLE%@!The FrontendMain object creates a separate RemoteLookupProxy actor to look up the boxOffice. In previous versions of Akka, you could use the actorFor method to directly get an ActorRef to the remote actor. This method has been deprecated, because the returned ActorRef didn’t behave exactly the same way as a local ActorRef in the case that the related actor died. An ActorRef returned by actorFor could point to a newly spawned remote actor instance, while this was never the case in a local context. At the time, remote actors couldn’t be watched for termination like local actors, which was another reason to deprecate this method.