Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka actorSelection vs actorOf Difference

Tags:

scala

akka

actor

Is there a difference between these two? When I do:

context.actorSelection(actorNameString)

I get an ActorSelection reference which I can resolve using the resolveOne and I get back a Future[ActorRef]. But with an actorOf, I get an ActorRef immediately. Is there any other vital differences other than this?

What might be the use cases where in I would like to have the ActorRef wrapped in a Future?

like image 856
joesan Avatar asked Jun 17 '15 06:06

joesan


People also ask

What is ActorRef in Akka?

java.io.Serializable. An ActorRef is the identity or address of an Actor instance. It is valid only during the Actor’s lifetime and allows messages to be sent to that Actor instance.

What is ActorSystem?

The ActorSystem is a root actor in actors structure. An ActorSystem is a hierarchical group of actors which share common configuration, e.g. dispatchers, deployments, remote capabilities and addresses. It is also the entry point for creating or looking up actors.

How can I send a message to an actor in Akka?

1) Akka Actor tell() Method It works on "fire-forget" approach. You can also use ! (bang) exclamation mark to send message. This is the preferred way of sending messages.

What is Akka typed?

Akka “Typed Actors”, now replaced by Akka Typed, were an implementation of the Active Objects pattern. Essentially turning method invocations into asynchronous dispatch instead of synchronous that has been the default way since Smalltalk came out.


1 Answers

actorOf is used to create new actors by supplying their Props objects.

actorSelection is a "pointer" to a path in actor tree. By using resolveOne you will get actorRef of already existing actor under that path - but that actorRef takes time to resolve, hence the Future.

Here's more detailed explanation: http://doc.akka.io/docs/akka/snapshot/general/addressing.html

An actor reference designates a single actor and the life-cycle of the reference 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.

like image 149
Piotr Rudnicki Avatar answered Oct 20 '22 02:10

Piotr Rudnicki