Creating actors

Next we will go ahead and try creating the TypedActor objects within the ActorSystem context.

An actor with a default constructor

When the typed actor implementation has a default constructor, it is constructed using the following syntax.

Java:

ActorSystem _system = ActorSytem.create("TypedActorsExample");
CalculatorInt calculator = TypedActor.get(_system)
  .typedActorOf(new TypedProps<Calculator>(
  CalculatorInt.class,	Calculator.class));

Scala:

    val _system = ActorSystem("TypedActorsExample")
    val calculator1: CalculatorInt =
    TypedActor(_system).typedActorOf(TypedProps[Calculator]())

The typed actor has been implemented as an Akka extension. So to get hold of the extension, the following call gets the extension object—TypedActor.get(_system) ...

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.