Akka Java example OneForOneStrategy does not compile

I am trying to insert OneForOneStrategy into a simple Hello-Akka program, for example, based on this documentation: http://doc.akka.io/docs/akka/2.3.2/java/fault-tolerance.html p>

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; } 

However, calls to resume / restart / stop / escalate do not compile out of the box. Why not?

+6
source share
2 answers

Just add the import listed below:

 import static akka.actor.SupervisorStrategy.escalate; import static akka.actor.SupervisorStrategy.restart; import static akka.actor.SupervisorStrategy.resume; import static akka.actor.SupervisorStrategy.stop; 
+4
source

I solved this problem. You just need to return SupervisorStrategy.resume (), SupervisorStrategy.restart () ... etc.

+2
source

Source: https://habr.com/ru/post/969614/


All Articles