主管策略RESTART,实际上没有重启我的孩子演员?

时间:2015-10-22 15:41:15

标签: scala akka supervisorstrategy

我有以下策略:

  override val supervisorStrategy = OneForOneStrategy(10, 10.seconds) {
    case e: JedisConnectionException => Restart
    case e: Exception => Restart
  }

从我所读过的内容(我认为我误解),每当儿童演员抛出未被捕获的异常时,它就会升级为父级演员。根据我上面的规则,如果我的孩子演员在接收时总是抛出异常,那么它应该重启10次吗?

出于某种原因,从我的日志来看,它看起来只是重新启动一次而且就是这样。我把日志放在了预启动和后期启动中。

编辑:

我意识到我犯了一个错误:

我正在使用" context.system.actorof()"这就是为什么没有一个儿童演员对策略做出反应。现在我使用" context.actorof()"而我确实看到例外情况已被抓住了#34;战略。

对于我的孩子演员,它需要与redis交谈以获取信息,我故意关闭我的redis以便让孩子演员失败,现在如果我设置我的主管策略重启最多10次,我应该看到相同的堆栈跟踪10次​​?

我是否正确地假设当重新启动子actor时,会再次向其发送相同的消息?

    2015-10-22 15:31:17,747 - [error] a.a.OneForOneStrategy - Error occurred trying to check for item existing in Redis:
java.lang.RuntimeException: Error occurred trying to check for item existing in Redis:
    at services.impl.RedisStatusServiceImpl.exists(RedisStatusServiceImpl.scala:62) ~[classes/:na]
    at w.c.Poller$$anonfun$process$1.apply(Poller.scala:64) ~[classes/:na]
    at w.c.Poller$$anonfun$process$1.apply(Poller.scala:58) ~[classes/:na]
    at scala.collection.immutable.List.foreach(List.scala:381) ~[scala-library-2.11.7.jar:na]
    at w.c.Poller.process(Poller.scala:58) ~[classes/:na]
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
    at redis.clients.util.Pool.getResource(Pool.java:50) ~[jedis-2.7.3.jar:na]
    at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99) ~[jedis-2.7.3.jar:na]
    at services.impl.RedisStatusServiceImpl.exists(RedisStatusServiceImpl.scala:58) ~[classes/:na]
    at w.c.Poller$$anonfun$process$1.apply(Poller.scala:64) ~[classes/:na]
    at w.c.Poller$$anonfun$process$1.apply(Poller.scala:58) ~[classes/:na]
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused
    at redis.clients.jedis.Connection.connect(Connection.java:164) ~[jedis-2.7.3.jar:na]
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:82) ~[jedis-2.7.3.jar:na]
    at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1641) ~[jedis-2.7.3.jar:na]
    at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:85) ~[jedis-2.7.3.jar:na]
    at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:861) ~[commons-pool2-2.3.jar:2.3]
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_05]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) ~[na:1.8.0_05]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_05]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_05]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_05]

1 个答案:

答案 0 :(得分:2)

是的,如果儿童演员到达maxNrOfRetries(在你的情况下是10)在时间窗口内重启(在你的例子中是10秒),它将被停止。

您可以在某些基本特征或抽象Actor类中定义全局supervisorStrategy。在这种情况下,所有actor类都是该BaseActor的子类。