Akka:如何让演员在主管身上引起异常
Akka : How to get actor causing exception on supervisor
我怎样才能知道哪个儿童演员对主管有例外。
基本上我想处理其他事情,比如将失败记录到数据库等。
在停止失败的演员之前。但为此我必须确切地知道哪个演员
有例外。
我的 supervisorStrategy 代码块像
/* stop task actor on unhandled exception */
private static SupervisorStrategy strategy = new OneForOneStrategy(
1,
Duration.create(1, TimeUnit.MINUTES),
new Function<Throwable, SupervisorStrategy.Directive>() {
@Override
public SupervisorStrategy.Directive apply(Throwable t) throws Exception {
return SupervisorStrategy.stop();
}
}
);
@Override
public SupervisorStrategy supervisorStrategy() {
return strategy;
}
当您观看child时,您将获得Terminated
message with actor
field and other info. See also What Lifecycle Monitoring Means. You can also process failure inside child actor itself, by overriding its preRestart
/postRestart
方法。
如果你阅读下面link关于Fault Tolerance的内容,你会发现在一个监督策略中,你可以根据这条信息得到失败的child actor ref :
If the strategy is declared inside the supervising actor (as opposed
to a separate class) its decider has access to all internal state of
the actor in a thread-safe fashion, including obtaining a reference to
the currently failed child (available as the getSender
of the failure
message).
因此,如果您在监督策略中使用 getSender
,您应该能够确定哪个 child 产生了异常并采取相应措施。
我怎样才能知道哪个儿童演员对主管有例外。 基本上我想处理其他事情,比如将失败记录到数据库等。 在停止失败的演员之前。但为此我必须确切地知道哪个演员 有例外。
我的 supervisorStrategy 代码块像
/* stop task actor on unhandled exception */
private static SupervisorStrategy strategy = new OneForOneStrategy(
1,
Duration.create(1, TimeUnit.MINUTES),
new Function<Throwable, SupervisorStrategy.Directive>() {
@Override
public SupervisorStrategy.Directive apply(Throwable t) throws Exception {
return SupervisorStrategy.stop();
}
}
);
@Override
public SupervisorStrategy supervisorStrategy() {
return strategy;
}
当您观看child时,您将获得Terminated
message with actor
field and other info. See also What Lifecycle Monitoring Means. You can also process failure inside child actor itself, by overriding its preRestart
/postRestart
方法。
如果你阅读下面link关于Fault Tolerance的内容,你会发现在一个监督策略中,你可以根据这条信息得到失败的child actor ref :
If the strategy is declared inside the supervising actor (as opposed to a separate class) its decider has access to all internal state of the actor in a thread-safe fashion, including obtaining a reference to the currently failed child (available as the
getSender
of the failure message).
因此,如果您在监督策略中使用 getSender
,您应该能够确定哪个 child 产生了异常并采取相应措施。