Reputation: 65
For Akka 2.2 how do I get a reference to a TypedActor. For untyped Actors we are advised to use ActorSelection and then use tell on ActorSelection. What should I do for TypedActor?
Upvotes: 0
Views: 618
Reputation: 35463
I don't use typed actors, but I'm going to take a shot at answering this question anyway based on the documentation and a little guess work. I don't believe Typed Actors and ActorSelection
s work directly together. If you think about an ActorSelection
, it's really a proxy to 0 to many actual ActorRef
s that match whatever query was used in the actorSelection
call that yielded it. This selection works well with untyped actors in cases where you want to broadcast the same message to a set of actors. Sitting a typed proxy in front of this seems to make less sense as I can't think of a ton of use cases where you want narrowed typing and to broadcast to a set of possible destinations and potentially receive responses (i.e. ask
).
Now, if you have an ActorSelection
, and you want to query that selection for a single ref under it (by using either Identify
or resolveOne
) and you get back an ActorRef
, then you can snap a typed actor proxy in front of it like so:
val typedActor =
TypedActor(system).typedActorOf(TypedProps[MyTypedActor],myLookedUpRef)
This technique basically takes a looked up untyped actor and narrows it into a TypedActor
that you can now communicate with via the TypedActor
s interface.
You can read more about TypedActor
s here and more about resolving ActorSelection
s here.
Upvotes: 2