I need a way to stop all the actor in an actorSystem upon certain Exception in one of the Actors. My idea was to change the default strategy of the Guardian Actor, setting an AllForOneStrategy with SupervisorStrategy.stop to every exception received.
The problem is that even if the application.conf is correctly loaded when an actor fails the system is still up.
prio-mailbox {
mailbox-type = "main.java.messages.MyPriorityMailbox"
//Other mailbox configuration goes here
}
akka{
actor{
guardian-supervisor-strategy = "main.java.engine.SupervisorStrategyGuardian"
}
}
This is the class that defines the supervisorstrategy
public class SupervisorStrategyGuardian implements SupervisorStrategyConfigurator {
@Override
public SupervisorStrategy create() {
return new AllForOneStrategy(//
10, //
Duration.create("10 seconds"), //
DeciderBuilder //
.matchAny(ex -> SupervisorStrategy.stop())
.build()); }
}
This is the Actor that generates all the other actors which can fail. As you can see if one of its child actors throws a AskTimeoutException it Escalade() so to reach the guardian Actor.
@Override
public SupervisorStrategy supervisorStrategy() {
return new OneForOneStrategy(//
10, //
Duration.create("10 seconds"), //
DeciderBuilder //
.match(AskTimeoutException.class, ex -> SupervisorStrategy.escalate()) // here i should stop all actors
// TODO --> check if escalating from maser triggers Actorsystem
.match(RuntimeException.class, ex -> SupervisorStrategy.restart()) //
.build());
}