I am using Akka (Java) in my project for providing a retry scheme. So I have a supervisor actor, which on receiving a message delegates it to a supervised actor. I have a one-for-one strategy on the supervisor to restart (unconditionally).
The supervised actor has a preRestart hook, which sends the message to self.
@Override
public void preRestart(Throwable reason, Option<Object> message){
//send it to the supervisor so that it can be enqueued once again to retry
if(reason.getCause() instanceof SQLException){
log.error("Not retrying since there seems to be a problem with the SQL itself!");
super.preRestart(reason, message);
}
else{
log.warn(""+state+" Trying to redo a processing: "+((RecordData)message.get()).getRecord());
getSelf().tell(message.get(), getSender());
super.preRestart(reason, message);
}
}
Now I want to preserve the internal state of the failed actor as well! I understand the state will be preserved only if my strategy is 'resume', but in that case the onRestart hook won't be invoked and the message will be lost.
Question:
1. Is the only way to achieve this, is to set the the state in the message itself and restart?
2. If the state maintains a sequential order, then I need to provide an 'ordered' mailbox implementation (dequeue based). Is that a correct understanding?