Akka Java在这里。我有两个演员,Parent
和Child
,其中前者是后者的父母。如果Child
引发特定异常(例如 an UnrulyTeenagerExcepton
),那么我正在寻找的行为如下:
- 保存对抛出异常时
Parent
正在处理的消息的引用;Child
然后 Child
重新启动,并将持久化的消息“回放”到Child
; 但- 如果这个保存 -> 重启 -> 重播循环发生了 3 次,并且
Child
抛出了UnrulyTeenagerException
3 次,那么我们SupervisorStrategy.escalate()
迄今为止我最好的尝试:
// 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()
}
}
但正如您所看到的,我正在努力解决消息持久性和回放问题。有任何想法吗?非常感谢 Java 代码示例,Akka 足够强悍,无需学习 Scala 象形文字!