我有以下代码:阿卡OneForOneStrategy不起作用
class A extends Actor with ActorLogging {
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 2) {
case _ => log.info("An actor has been killed"); Restart
}
val b = context.system.actorOf(Props[B], "b")
def receive = {
case _ => context.system.scheduler.schedule(5 seconds, 5 seconds, b, true)
}
}
class B extends Actor with ActorLogging {
def receive = { case true => self ! Kill }
}
在演员A
实例self ! Kill
后,我没有看到一个消息,“一个演员已被杀死”,并随后调用演员A
产生“死信”消息,所以没有重新启动。为什么OneForOneStrategy
没有被调用?
奇怪的是,我可以删除整个OneForOneStrategy
覆盖,程序行为没有任何变化。
好的,但是'maxNrOfRetries = 2'应该是这样吗?我意识到无限循环,但我认为这应该在父母演员'A'重试两次后终止,因为这个选项非常有用。 – Anton
@Anton好吧,如果调用postRestart,这意味着Actor已成功重启。所以重试次数是1. – wheaties
我还是不明白。我看到它的方式应该是这样的:开始 - >失败 - >重启#1 - >失败 - >重启#2 - >失败 - >因为maxNrOfRetries = 2停止。我错过了什么吗? – Anton