andruha
andruha

Reputation: 65

How to acquire actor reference to typed actor implementation in Akka?

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

Answers (1)

cmbaxter
cmbaxter

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 ActorSelections work directly together. If you think about an ActorSelection, it's really a proxy to 0 to many actual ActorRefs 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 TypedActors interface.

You can read more about TypedActors here and more about resolving ActorSelections here.

Upvotes: 2

Related Questions