O'Reilly logo

Akka Essentials by Munish K. Gupta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining an actor

To define a typed actor, two things are required—a public interface, and secondly, an implementation of the interface. Let's create a simple calculator interface that does some simple tasks such as addition, subtraction, and counter updating.

Java:

public interface CalculatorInt {

    public Future<Integer> add(Integer first, Integer second);

    public Future<Integer> subtract(Integer first, 
                          Integer second);

    public void incrementCount();

    public Option<Integer> incrementAndReturn();

}

Scala:

trait CalculatorInt {

    def add(first: Int, second: Int): Future[Int]

    def subtract(first: Int, second: Int): Future[Int]

    def incrementCount(): Unit

    def incrementAndReturn(): Option[Int]
}

An important thing to note here is the method return types as follows: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required