Quantcast
Channel: Akka Libraries - Discussion Forum for Akka technologies
Viewing all articles
Browse latest Browse all 1365

Capability of creating children to an arbitrary actor from anywhere in an application without messaging it

$
0
0

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.ActorSystem has its correspondence in akka.actor.typed.ActorSystem. One difference is that when creating an ActorSystem in Typed you give it a Behavior that 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 classic ActorSystem, such initialization is typically performed from the “outside”.
The actorOf method of the classic ActorSystem is typically used to create a few (or many) top level actors. The ActorSystem in 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 SpawnProtocol to 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.

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1365

Trending Articles