简体   繁体   English

Java Akka - 从父上下文向子动作广播消息

[英]Java Akka - Broadcasting Message to Child Actors from Parent Context

ActorSelection selection =   context.actorSelection( "/user/ParentActor/*");
selection.tell(msg,null);

Assumming the parent actor context presented here in the example has more than 1 actor. 在示例中假设父元件上下文具有多个actor。

Does the above tell statement send message to all child actors sequentially or parallely.That is whether the tell statement behave like a broadcastor or internally an iteration is performed to send message to each actor in the selection 上面的tell语句是顺序地还是并行地向所有子actor发送消息。这就是tell语句的行为是广播还是内部执行迭代以向选择中的每个actor发送消息

Looking here (which is the method called by the tell) it seems to use an iterator, so I'd say sequential. 这里 (这是tell所调用的方法)它似乎使用了一个迭代器,所以我会说顺序。

Nonetheless, it's a quite lightweight operation, so you shouldn't worry too much about it. 尽管如此,这是一个非常轻量级的操作,所以你不必过于担心它。

If you're concerned about performance, it might be better to keep track of the actors, or to use an event bus. 如果您关注性能,那么跟踪演员或使用事件总线可能会更好。 In an event bus you can have the actors subscribe to a topic and then you broadcast the message through the event bus. 在事件总线中,您可以让演员订阅主题,然后通过事件总线广播消息。 http://doc.akka.io/docs/akka/snapshot/java/event-bus.html http://doc.akka.io/docs/akka/snapshot/java/event-bus.html

You could also use a router to broadcast to all children. 您还可以使用路由器向所有孩子广播。 http://doc.akka.io/docs/akka/snapshot/scala/routing.html http://doc.akka.io/docs/akka/snapshot/scala/routing.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM