I'm experimenting with OneForOneStrategy
strategy, which escalates the failure. My structure of Actor is: Supervisor -> Slave
, where Slave is child of Supervisor.
Slave responds to 2 messages - "fail" (throws exception) and "work" (makes some logging)
My first problem was that if Slave failed, then Supervisor got restarted (because of the escalation strategy, the "Guardian" have restarted it), however Slave was stopped and not restarted.
I guess there is a reason to this default behavior of stopping the children instead of restarting them. Could you please explain this design decision? In which cases is this a better approach than restart ?
My problem with the behavior was that Slave's inbox looked like this: "work", "fail", "work".
After the failure, the last "work" message ended in Dead Letter, since the Slave was stopped & started (by initialization of Supervisor).
The solution was to override the preRestart
method:
@Override
public void preRestart(Throwable reason, Optional<Object> message) throws Exception {
postStop();
}
This fixed the problem and caused the children to be restarted. I also had to change the initialization of Slave in Supervisor.