Actor Typed Context

Is there a method to create a typed actor outside of the actor context? The untyped actor system had the actorOf function, but I cannot find any equivalent way to spawn a typed actor.

Regards,

There are basically three ways to spawn an actor in Typed:

  • via an actor’s context
  • on ActorSystem creation, by specifying the behavior of the guardian actor
  • as a system actor by calling the systemActorOf method on the ActorSystem

The second way is generally only used once per-JVM (since one should generally only have one ActorSystem per JVM). The third way is only really intended for library/extension authors. So that leaves spawning via an ActorContext as the one general way to do this, which is useful for guiding one to think about the parent-child relationship.

Of course, it is entirely possible to, once you have an actor, send it a message containing the behavior (and perhaps name) of an actor you want it to spawn and that actor uses its context to spawn a child: the actor then replies with the spawned ActorRef. This interaction is captured in the SpawnProtocol: one typical pattern is having the guardian behavior for the actor system handle this protocol.