Creating an actor hierarchy

To create child actors under a typed actor, we need to get the TypedActor context and then invoke the actorOf method.

Java:

//create a child actor under the Typed Actor context
ActorRef childActor = TypedActor.context().actorOf(
            new Props(ChildActor.class), "childActor");

Scala:

import TypedActor.context
//create a child actor under the Typed Actor context
val childActor:ActorRef = context.actorOf(Props[ChildActor],name="childActor")

Note

Remember, TypedActor.context() is only valid within methods of a TypedActor implementation.

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.