Akka定制主管未生效

时间:2016-02-12 05:16:22

标签: scala akka actor supervisor supervisorstrategy

在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}
    }
  }
}

我的演员实例化如此

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的默认策略。

1 个答案:

答案 0 :(得分:1)

我认为应该是

akka.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"
}