Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gracefully restart entire Akka actor system

Tags:

akka

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.

like image 291
Robin Green Avatar asked Jan 23 '13 14:01

Robin Green


1 Answers

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
}
like image 184
Roland Kuhn Avatar answered Oct 14 '22 22:10

Roland Kuhn