2015-10-22 82 views
1

我有以下STRAT:主管戰略重新啓動,實際上並沒有重新啓動我的孩子演員?

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

從我讀過的(我想我誤解),當童星拋出了心不是捕獲的異常,它升級到父演員。根據我上面的規則,如果我的孩子演員總是在接收時拋出異常,不應該重新啓動10次?

出於某種原因,從我的日誌中,它看起來像只是重新啓動一次,就是這樣。我把日誌放在prestart和poststart中。

編輯:

我意識到一個錯誤,我做:

我所用「context.system.actorof()」這就是爲什麼沒有一個兒童演員被反應到STRAT。現在我使用「context.actorof()」,我確實看到這個例外被這個策略「抓住」了。

對於我的孩子演員,它需要與redis交談獲取信息,並且我故意關閉我的redis,這樣孩子演員就會失敗,現在如果我將主管策略設置爲重新啓動10次,我應該看到相同堆棧跟蹤10次?

我正確地認爲,當一個小孩演員重新啓動時,發送的同一條消息會再次發送給它嗎?

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] 

回答

2

是,如果一個兒童演員達到maxNrOfRetries(在你的案件10)的時間窗口(10秒在你的例子)內重新啓動,它會被停止。

例如,您可以在一些基本特徵或抽象Actor類中定義全局supervisorStrategy。所有演員類都在這種情況下是該BaseActor的子類。

+0

ive updated op .. – iCodeLikeImDrunk