Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "ask" an ActorSelection

Tags:

scala

akka

How do I "ask" an actor that should be provided by its path?

ask(context.actorSelection("../foo"), GetInfoMessage)

…results in an ActorSelection but only ActorRefs can be "asked". Alternatively, context.actorFor returns an ActorRef, but this function is deprecated according to the documentation.

like image 879
hiddenbit Avatar asked Apr 19 '13 13:04

hiddenbit


2 Answers

Since Akka 2.2.1 you can use ActorSelection.resolveOne to get an ActorRef from a selection:

http://doc.akka.io/api/akka/2.2.1/index.html#akka.actor.ActorSelection

Then you can ask the ActorRef as you normally do

like image 179
Andrejs Avatar answered Nov 04 '22 01:11

Andrejs


Later on that page you will see

To acquire an ActorRef that is bound to the life-cycle of a specific actor you need to send a message, such as the built-in Identify message, to the actor and use the sender reference of a reply from the actor.

So it's a three step process. Use actorSelection, then send Identify, then ask.

This is only for Akka 2.2 though, so in Akka 2.1 or prior you still need to use actorFor.

The rationale is explained in the 2.2 Migration Guide.

like image 25
sourcedelica Avatar answered Nov 04 '22 01:11

sourcedelica