Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Akka Java OneForOneStrategy example not compiling

Tags:

java

akka

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?

like image 438
HiChews123 Avatar asked May 21 '14 01:05

HiChews123


People also ask

What is Akka in Java and Scala?

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.

Why should I organize my Akka actors in a hierarchy?

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:

What is the use case for Akka in IoT?

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.

What is createreceive () method in Akka?

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.


Video Answer


2 Answers

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;
like image 186
Yevgen Nerush Avatar answered Sep 20 '22 17:09

Yevgen Nerush


I've resolved this issue. You just need to return SupervisorStrategy.resume(), SupervisorStrategy.restart() ... etc.

like image 36
HiChews123 Avatar answered Sep 18 '22 17:09

HiChews123