在不关闭系统本身的情况下停止系统中的所有参与者? [英] stop all actors in a system without shutting down the system itself?

查看:40
本文介绍了在不关闭系统本身的情况下停止系统中的所有参与者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Akka 2.0中,是否有一种很好的方法来关闭/ user路径下的所有actor?例如,假设我执行以下操作:

In Akka 2.0, is there a nice way to shut down all actors under the path /user? For example, let's say that I do the following:

val system = ActorSystem.create("mySystem")

system.actorOf(Props(new MyActor1), "actor1")
system.actorOf(Props(new MyActor2), "actor2")

一段时间后,我决定要停止系统中的所有参与者。如果我正确理解所有内容,则actor1和actor2将是路径/ user的子代,但是我看不到有一种方法可以让我迭代ActorRef的子代。有另一种方法吗?

Some time later, I decide I want to stop all of the actors in the system. If I understand things correctly, actor1 and actor2 will be children of the path /user, but I don't see a method that gives me an iterable of the children of an ActorRef. Is there another way?

推荐答案

使用演员选择将PoisonPill发送给所有顶级演员:

Use an actor selection to send a PoisonPill to all top-level actors:

system.actorSelection("/user/*") ! PoisonPill

这篇关于在不关闭系统本身的情况下停止系统中的所有参与者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆