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?
In Akka, you can stop Actors by invoking the stop() method of either ActorContext or ActorSystem class. ActorContext is used to stop child actor and ActorSystem is used to stop top level Actor.
Stopping Actors A child actor can be forced to stop after it finishes processing its current message by using the stop method of the ActorContext from the parent actor.
2) postStop() This method is used to release resources after stopping the Actor. It may be used for deregistering this Actor. Messages sent to a stopped actor will be redirected to the deadLetters of the ActorSystem.
Use an actor selection to send a PoisonPill to all top-level actors:
system.actorSelection("/user/*") ! PoisonPill
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With