I'm trying to paste the OneForOneStrategy into a simple Hello-Akka program, like so based on this documentation: 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;
}
However, the resume/restart/stop/escalate method calls don't compile out of the box. Why not?
Introduction Akka is an open-source library that helps to easily develop concurrent and distributed applications using Java or Scala by leveraging the Actor Model. In this tutorial, we'll present the basic features like defining actors, how they communicate and how we can kill them.
By organizing the actors in a hierarchy, each actor can notify its parent of the failure, so it can act accordingly. The parent actor can decide to stop or restart the child actors. 3. Setup To take advantage of the Akka actors we need to add the following dependency from Maven Central:
IoT example use case. In this tutorial, we’ll use Akka to build out part of an Internet of Things (IoT) system that reports data from sensor devices installed in customers’ homes. The example focuses on temperature readings. The target use case allows customers to log in and view the last reported temperature from different areas of their homes.
Any Akka actor will extend the AbstractActor abstract class and implement the createReceive () method for handling the incoming messages from other actors: public class MyActor extends AbstractActor { public Receive createReceive() { return receiveBuilder ().build (); } } This is the most basic actor we can create.
Just add 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;
I've resolved this issue. You just need to return SupervisorStrategy.resume(), SupervisorStrategy.restart() ... etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With