Reputation: 1686
i m using two different ways for get the same result but at one i need to specify a call back time why ? Them dose the same things ?
ActorRef resolveActorRef = getContext().getSystem()
.provider() .resolveActorRef(ActorPath.fromString("akka://RootRemoteActors/user/$a/remote.actors.AA"));
The code above retrive an actor Ref without waiting any time Why if i do not get the proveider i have to specify a time duration?
ActorSelection actorSelection = getContext().getSystem()
.actorSelection( ActorPath.fromString("akka://RootRemoteActors/user/$a/remote.actors.AA"));
ActorRef ois = actorSelection.resolveOne( new Timeout(1000, TimeUnit.MILLISECONDS ))
.value().get().get();
Upvotes: 1
Views: 785
Reputation: 2173
The most obvious difference is probably that an ActorSelection
can represent multiple ActorRef
s if you use wildcards in the actor path. So if you just call .tell
on your actorSelection
instead of resolveOne
you deliver the message to all matching actors.
I never used resolveActorRef
but from what I can see from the sources (ActorRefProvider and ActorSelection) ActorRefProvider
uses getChild
on the rootGuardian
to find that Actor
you are looking for and therefore traverses from the top of your actor tree down until he finds it eventually (or not).
ActorSelection
tries to send an Identify
message using the ask-pattern (therefore the timeout) to the selection and if it receives a response it will provide the ActorRef
from which it got the response.
resolveActorRef
seems to be used if you write your own serializer: Akka Docs, so if you just want to resolve an actor, I would go with the ActorSelection
(which you btw. don't have to resolve in order to send a message to it).
Upvotes: 1