Assuming I have a parent
actor that sends one message at a time to its child
actor.
When the child is done processing the current message it notifies the parent that in it turn will send a new message to the child.
In order to keep this loop even if the child crashs on a certain message, I added a SupervisorStrategy to the parent:
private static SupervisorStrategy strategy =
new OneForOneStrategy(10, Duration.create("1 minute"),
new Function<Throwable, SupervisorStrategy.Directive>() {
@Override
public SupervisorStrategy.Directive apply(Throwable t) {
if (t instanceof NullPointerException) {
return resume();
} else {
return escalate();
}
}
});
The idea is that no matter what heppens to the child, it will resume and the parent will be able to send it the next message.
But how the parent knows when the error occured, in order to send the next message?
What is the trigger for the parent that something happend to the child?
Is there something like "onChileError" method that I need to override?
(will appriciate a Java over Scala example)
Thanks.