Akka Java here. I have two actors, Parent
and Child
, where the former is the parent of the latter. If Child
throws a specific exception (say, an UnrulyTeenagerExcepton
), then the behavior I am looking for is as follows:
- The
Parent
saves a reference to the message that was being processed byChild
when the exception was thrown; then Child
is restarted, and the persisted message is “played back” to theChild
; but- If this save -> restart -> replay cycle happens three times, and the
Child
throws theUnrulyTeenagerException
three times, then weSupervisorStrategy.escalate()
My best attempt thus far:
// Groovy pseudo-code
class ChildFailureDecider extends Function<Throwable,Directive> {
int maxRetries = 3
int numRetries = 0
@Override
Directive apply(Throwable childFailure) {
if(childFailure instanceof UnrulyTeenagerException) {
numRetries++
if(numRetries <= maxRetries) {
// TODO: #1 How to persist the message that caused the ‘childFailure’?
return SupervisorStrategy.restart()
// TODO: #2 How to ‘play back’ the persisted message to Child?
}
}
SupervisorStrategy.escalate()
}
}
But as you can see, I’m struggling with message persistence and play back. Any ideas? Java code samples greatly appreciated, Akka is tough enough without also having to learn Scala hieroglyphics!