Hi,
I have received excellent answers in my previous post, thus I’d like to take the opportunity to make some more questions.
I am making these questions in the context of my master thesis, for which I desire to understand Akka’s design. In particular, I always wonder “Why does Akka do things this way? Is there a philosophical or technical reason?”.
I am reading Learning Akka Typed from Classic:
akka.actor.ActorSystemhas its correspondence inakka.actor.typed.ActorSystem. One difference is that when creating anActorSystemin Typed you give it aBehaviorthat will be used as the top level actor, also known as the user guardian.
Additional actors for an application are created from the user guardian alongside performing the initialization of Akka components such as Cluster Sharding. In contrast, in a classicActorSystem, such initialization is typically performed from the “outside”.
TheactorOfmethod of the classicActorSystemis typically used to create a few (or many) top level actors. TheActorSystemin Typed doesn’t have that capability. Instead, such actors are started as children of the user guardian actor or children of other actors in the actor hierarchy.
So far, I understand. My questions come from the remaining of the paragraph:
The rationale for this is partly about consistency. In a typed system you can’t create children to an arbitrary actor from anywhere in your app without messaging it, so this will also hold true for the user guardian actor. That noted, in cases where you do need to spawn outside of this guardian then you can use the
SpawnProtocolto spawn as needed.
Where does this limitation come from?
My guess is that, in Akka Classic, we have a full Actor object exposing an ActorContext: whoever has such ActorContext can arbitrary create children to such actor.
In Akka Typed, instead, we only ever have a typed ActorRef of an actor, so we lose the capability in question.
I am wondering what are the reasons for Akka Typed for not returning a typed ActorRef together with a typed ActorContext, or similar. This would overcome the limitation in question.
Perhaps there is a “philosophical” argument for this, constituted by the design principle that the only way of changing an actor’s state must happen through means of message passing (thus, including adding a child to it).
Thanks to anyone who will answer.