【发布时间】:2016-05-23 04:06:32
【问题描述】:
在 src/main/resources/application.conf 中
actor {
# The guardian "/user" will use this class to obtain its supervisorStrategy.
# It needs to be a subclass of akka.actor.SupervisorStrategyConfigurator.
# In addition to the default there is akka.actor.StoppingSupervisorStrategy.
guardian-supervisor-strategy = "config.ResilientSupervisorStrategy"
}
指的是以下内容:
package config
import akka.actor._
import akka.actor.SupervisorStrategy._
final class ResilientSupervisorStrategy extends SupervisorStrategyConfigurator {
override def create(): SupervisorStrategy = {
OneForOneStrategy(){
case _: ActorInitializationException ⇒ Stop
case _: ActorKilledException ⇒ Stop
case _: DeathPactException ⇒ Stop
case _: Exception ⇒ Resume}
}
}
}
我的 Actor 是这样实例化的
object Singleton {
val actorSystem = ActorSystem("main")
val logger: ActorRef = actorSystem.actorOf(Props(new Logger()))
}
和
val miner: ActorRef =
Singleton.actorSystem.actorOf(Props(new Miner()))
但是,当miner 遇到异常时,它仍然会重新启动(它仍然使用默认的主管策略)
作为旁注,我的演员有非常简单的内部状态。所有失败都是由于外部资源造成的(即,Futures 没有返回,因为服务器发送了错误的响应),因此不需要重启 actor 的默认策略。
【问题讨论】:
-
你能展示你的actor实例化的代码吗?
-
我添加了实例化代码。
标签: scala akka akka-supervision akka-actor