我正在尝试将OneForOneStrategy粘贴到一个简单的Hello-Akka程序中,就像基于这个文档一样:http://doc.akka.io/docs/akka/2.3.2/java/fault-tolerance.html
private static SupervisorStrategy strategy = new OneForOneStrategy(10,
Duration.create("1 minute"),
new Function<Throwable, SupervisorStrategy.Directive>() {
@Override
public SupervisorStrategy.Directive apply(Throwable t) {
if (t instanceof ArithmeticException) {
return resume();
} else if (t instanceof NullPointerException) {
return restart();
} else if (t instanceof IllegalArgumentException) {
return stop();
} else {
return escalate();
}
}
}
);
@Override
public SupervisorStrategy supervisorStrategy() {
return strategy;
}
Run Code Online (Sandbox Code Playgroud)
但是,resume/restart/stop/escalate方法调用不会立即编译.为什么不?
只需添加下面列出的导入:
import static akka.actor.SupervisorStrategy.escalate;
import static akka.actor.SupervisorStrategy.restart;
import static akka.actor.SupervisorStrategy.resume;
import static akka.actor.SupervisorStrategy.stop;
Run Code Online (Sandbox Code Playgroud)