Strange behaviour ActorSelection

Hi All,

(Akka Java latest) In the constructor of an actor I’ve the following printlin

[DEBUG] [06/08/2018 21:59:49.852] [test-akka.actor.default-dispatcher-13] [akka://test/user/TestSupervisor/PharmaSupervisor/$a/TrialManager-pharma_ct_1]  My path is Actor[akka://test/user/TestSupervisor/PharmaSupervisor/$a/TrialManager-pharma_ct_1#-1946840248]

all good. However, when I try (running the program as Main from bash) to get the ActorRef using actorSelection I have:

Patient::getClinicalTrialRef: going on actor selection ActorSelection[Anchor(akka://test/), Path(/user/TestSupervisor/PharmaSupervisor/*/TrialManager-pharma_ct_1)] 

but the reference is empty. I am using this code:

 ActorSelection selection = getContext().actorSelection(
                "akka://test/user/TestSupervisor/PharmaSupervisor/*/TrialManager-"
                        + trialId);
        l.debug("Patient::getClinicalTrialRef: going on actor selection  {} ", selection);
        Timeout timeout = new Timeout(
                scala.concurrent.duration.Duration.create(60, "seconds"));
        Option<Try<ActorRef>> v = selection.resolveOne(timeout).value();
        return v;

and v is empty. Notably, if I run it in eclipse, it works. If I remove (from the selection criteria), the akka://test/user, it finds the actor reference, but then it says that the actor does not exist.

Any idea?

Sorry for the probably naive question.

Could it be that the value() of the Future is not completed yet?

If inside actor I’d recommend using messages rather than mixing resolveOne futures. There is an example of using Identify/ActorIdentity messages in the documentation.

Or perhaps you can pass in the ActorRef as a constructor parameter instead of using ActorSelection in the first place?

1 Like