0

I create a RouterPool of an actor like this:

val myActorPool = Akka.system.actorOf(RoundRobinPool(5).props(Props[MyActor]), "myActor")

now i would like to access the ActorRef objects of the 5 children that are managed by this router. Is there some method call to retrieve that for all children? Or do i have to declare them explicitly and then pass them to the router?

samy
  • 1,396
  • 2
  • 19
  • 41
  • If you want control over the children you might consider a round robin group instead of a pool. – cmbaxter May 19 '15 at 11:11
  • Ok so i guess this means that there is now easy method call to get the actorRefs from a pool and i have to declare them explicitly and add them to the group. – samy May 19 '15 at 12:47
  • Yes. The pooled actors are meant to be out of your control. If you need control over them use a group. – cmbaxter May 19 '15 at 14:05

3 Answers3

2

Sending akka.routing.GetRoutees to a router actor will make it send back its currently used routees in a akka.routing.Routees message

from: http://doc.akka.io/docs/akka/2.3.11/scala/routing.html#Managagement_Messages

planetenkiller
  • 729
  • 5
  • 15
  • Ok this doesn't return actual ActorRef objects but Routee seems to be sufficient for my purpose. – samy May 29 '15 at 07:47
0

A bit late to the party but here's how I did it, provided you're using Routees that are ActorRefRoutee:

val actor: Option[ActorRefRoutee] = myActorPool.logic.select("Hello", routees /*Should be able to generate these from router*/) match { 
 case actorRefRoutee: ActorRefRoutee => 
   Some(actorRefRoutee) 
 case _ => 
   None
}

then you can get the actor reference by calling:

actor.ref
0

A long time has passed and I had the same question about Akka.Net and did not find a working answer. Discovering type of the returned objects in the debugger helped me:

_router.Tell(new GetRoutees());
...
// router callback
var routees = message as Routees;
if (routees != null)
{
    IEnumerable<IActorRef> routeeRefs = routees.Members.Select(r => ((ActorRefRoutee) r).Actor);
    ...
}
Oleg
  • 1,291
  • 13
  • 16