Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop all actors in a system without shutting down the system itself?

Tags:

scala

akka

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?

like image 460
jxstanford Avatar asked Feb 20 '12 06:02

jxstanford


People also ask

How do you stop an actor system?

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.

How do you stop an actor in Java?

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.

What does the life cycle postStop do?

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.


1 Answers

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

system.actorSelection("/user/*") ! PoisonPill
like image 117
Roland Kuhn Avatar answered Sep 28 '22 19:09

Roland Kuhn