How can I gracefully restart an entire actor system? In other words, stop all the actors in the system with a gracefulStop (or at least the important ones!)
Basically I want to, in effect, restart the application during a test, without the overhead of starting up a new separate JVM each time.
I'm using Akka 2.0.5.
Whenever you have implemented an actor system and it is lacking one function, don’t hesitate to add one more actor to take care of that: in this case create one actor whose job is it to send graceful stop requests to your important actors and await their termination. That actor can then shut down the actor system, while from the outside you awaitTermination. If you created that actor with system.actorOf(Props[Terminator], "terminator"), then you can shut it down with
system.actorFor("/user/terminator") ! MakeItStop // or whatever message you choose
try system.awaitTermination(1.minute) // or however long it may take
catch {
case _: TimeoutException => system.shutdown() // as a last resort
}
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