stop all actors in a system without shutting down

2019-04-28 22:12发布

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")

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?

标签: scala akka
1条回答
虎瘦雄心在
2楼-- · 2019-04-28 22:34

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

system.actorSelection("/user/*") ! PoisonPill
查看更多
登录 后发表回答