【发布时间】:2017-02-09 00:54:56
【问题描述】:
我将在未来的通话中执行某些操作。我将在成功完成时将结果返回给发送者,或者如果未来的调用失败,则让参与者失败。这将由实现具有监督策略的 RoundRobinPool 的父级处理。
这里是代码sn-p。
private def getData(sender: ActorRef): Unit = {
dao.getData().mapTo[List[Data]].map(result => sender ! result)
.onFailure {
case e: NullPointerExcetpion => {
println("+++++++ Throwing exception")
// throwning the exception from here doesn't cause the supervisor to restart this actor
throw t
}
}
// throwing the exception from here makes the supervisor strategy to take action
throw new NullPointerExcetpion
}
如果future返回异常,我们如何让actor失败?
干杯,
乌萨夫
【问题讨论】:
-
你所说的“失败的演员”是什么意思?
-
将其传播回用户并杀死参与者。会导致主管重新启动actor的行为。由于 SupervisorStrategy.Restart 用于在出现空指针异常的情况下在主管中。
-
更重要的是,为什么当我从 Future 函数之外显式抛出错误时它会起作用?