6
votes

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?

1
You might not want to create a lot of actors under the root directly, since that creates a very shallow but wide tree. Create one level first, and then PoisonPill that one?Viktor Klang
I originally thought this didn't apply to my problem, but after more consideration, I think another layer of actors might be in order. I am basically managing connections for a service, and the connections are hanging directly from the actor system. I believe I'll add support for a connection container. Thanks!jxstanford

1 Answers

13
votes

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

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