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 an actor, the class needs to extend the actor and implement the required abstract method for handling messages.

Java:

public class MyActor extends UntypedActor {
  public void onReceive(Object message) throws Exception {
  }
}

Scala:

class MyActor extends Actor {
  def receive = {
  }
}

An Actor class can also have non-default constructors. So any data that needs to be passed at the time of the object creation can be passed to the Actor object. In Scala, the receive block is actually a partial function, which allows the usage of pattern matching syntax.

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