我像这样创建一个演员的RouterPool:
val myActorPool = Akka.system.actorOf(RoundRobinPool(5).props(Props[MyActor]), "myActor")
现在我想访问由此路由器管理的5个孩子的ActorRef对象。是否有一些方法调用来检索所有孩子的?或者我必须明确声明它们然后将它们传递给路由器?
将
akka.routing.GetRoutees
发送给路由器actor将使其在akka.routing.Routees
消息中发回其当前使用的路由
来自:http://doc.akka.io/docs/akka/2.3.11/scala/routing.html#Managagement_Messages
派对有点晚了,但是这就是我如何做到的,只要你使用Routee
s是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
}
那么你可以通过调用获取actor引用:
actor.ref
很长一段时间过去了,我对Akka.Net提出了同样的问题,并没有找到合适的答案。在调试器中发现返回对象的类型帮助我:
_router.Tell(new GetRoutees());
...
// router callback
var routees = message as Routees;
if (routees != null)
{
IEnumerable<IActorRef> routeeRefs = routees.Members.Select(r => ((ActorRefRoutee) r).Actor);
...
}