[英]Possible to specify custom Routees or custom constructor arguments for each Actor
I imagine this might not be possible because of supervision strategies needing to recreate actors, nevertheless am I able to feed custom actors to a Router? 我想这可能是不可能的,因为需要重新创建演员的监督策略,但是我能够将自定义演员提供给路由器吗? Or at the very least: custom constructor arguments? 或者至少:自定义构造函数参数?
If no, why doesn't akka allow this? 如果不是,为什么akka不允许这样做? Is routing not suppose to be used in this way? 路由不是假设以这种方式使用? I am using a BalancingPool by the way. 顺便说一句,我正在使用BalancingPool。
This seems to be possible in Scala How to create routers in akka with parameterized actors? 这似乎可以在Scala 中使用参数化的actor在akka中创建路由器? but I haven't been able to figure this out in java. 但我无法在java中解决这个问题。
It is not possible with a pool, since a pool creates multiple instances of from the same Props
definition, but it is possible with routing in general. 池不可能,因为池创建了来自相同Props
定义的多个实例,但通常可以使用路由。 From the docs: 来自文档:
This type of router actor comes in two distinct flavors: 这种类型的路由器演员有两种不同的风格:
- Pool - The router creates routees as child actors and removes them from the router if they terminate. 池 - 路由器创建路由器作为子actor,如果它们终止则将它们从路由器中删除。
- Group - The routee actors are created externally to the router and the router sends messages to the specified path using actor selection, without watching for termination. 组 - 在路由器外部创建routee actor,路由器使用actor选择将消息发送到指定路径,而不监视终止。
Do if you create a group rather than a pool, the group can contain whichever actors you want. 如果您创建组而不是池,则该组可以包含您想要的任何演员。
From the Routing documentation : 从路由文档 :
public class Master extends UntypedActor {
Router router;
{
List<Routee> routees = new ArrayList<Routee>();
for (int i = 0; i < 5; i++) {
ActorRef r = getContext().actorOf(Props.create(Worker.class));
getContext().watch(r);
routees.add(new ActorRefRoutee(r));
}
router = new Router(new RoundRobinRoutingLogic(), routees);
}
// ...
}
So you can create the routees the way you want. 因此,您可以按照自己的方式创建路线。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.