你是对的,除了它在默认决策者规则中包含可抛出对象(即错误)和异常,并且它在 Actor 抛出可抛出对象时运行。根据http://doc.akka.io/docs/akka/2.0/java/fault-tolerance.html#default-supervisor-strategy,默认情况下如果没有定义supervisor策略或者没有覆盖(用户创建的)Actor抛出的异常,会依次执行以下规则,直到触发:
- ActorInitializationException 将停止失败的子actor
- ActorKilledException 将停止失败的子actor
- 其他异常将重新启动失败的子actor
- 其他类型的 Throwable 将升级到父级actor
如果您还没有看过,请在http://doc.akka.io/docs/akka/2.3.11/general/supervision.html 上查看监督的正常评论。
Derek Wyatt 在“Akka Concurrency”第 8 章中对它进行了很好的代码级讨论。它主要处理 Scala 版本,但我相信 Actor 错误处理是在 Scala 中实现的(依赖于 Java)。
查看 2.3.11 的源代码,默认的 Actor 故障处理决策器位于 akka-actor_2.11-2.3.11-sources.jar\akka\actor.FaultHandling.scala 中,并且是:
/**
* When supervisorStrategy is not specified for an actor this
* [[Decider]] is used by default in the supervisor strategy.
* The child will be stopped when [[akka.actor.ActorInitializationException]],
* [[akka.actor.ActorKilledException]], or [[akka.actor.DeathPactException]] is
* thrown. It will be restarted for other `Exception` types.
* The error is escalated if it's a `Throwable`, i.e. `Error`.
*/
final val defaultDecider: Decider = {
case _: ActorInitializationException ⇒ Stop
case _: ActorKilledException ⇒ Stop
case _: DeathPactException ⇒ Stop
case _: Exception ⇒ Restart
}
/**
* When supervisorStrategy is not specified for an actor this
* is used by default. OneForOneStrategy with decider defined in
* [[#defaultDecider]].
*/
final val defaultStrategy: SupervisorStrategy = {
OneForOneStrategy()(defaultDecider)
}
这与文档一致 - 越来越少,因为 defaultDecider 不包含显式
case _ => Escalate // _ is the scala wildcard for anything
在 makeDecider 函数中实现,如果 Throwable 与 defaultDecider 不匹配,则默认为 Escalate;并且文档没有提到包含 DeathPactException 的规定可能是为了减少与细节的混淆。