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: ...

Get Akka Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.