In my Akka system there is a top-level ("root") actor, Initializer
, from which all other actors come from. There is also an actor, Destroyer
, that is responsible for shutting down the system gracefully when it receives a Destroy
message. There are several conditions under which an actor would send a Destroy
to the Destroyer
, but those don't really matter here.
I would now like to implement functionality in Initializer
's SupervisorStrategy
where, if it can't handle a failure/exception thrown by one of its chidren, it will interpret that as a "stop the world"-type event, and shut the system down gracefully.
My knee jerk reaction is to have Initializer
escalate the failure, but I'm not sure what happens when the top-most actor escalates. It would be nice if there was a way for that escalation to somehow invoke the Desroyer
, but not sure how to wire that all up. Any ideas?
I answered a similar question here: How to escalate top-most supervisors in Akka?
Essentially, in your configuration set:
akka.actor.guardian-supervisor-strategy = "akka.actor.StoppingSupervisorStrategy"
Then in your Initializer
you should escalate any exceptions which you want to be fatal for the system. The Initializer will then be stopped. You could watch the Initializer
from the Destroyer
and react to the Terminated
event, or if you want to stick to your custom Destroy
message, send Destroy
to the Destroyer
from postStop()
within the Initializer
.