cbear
cbear

Reputation: 35

Defining AKKA Actor hierarchies

Understand all AKKA Actors are derived from /user guardian Actor. In order to take care of the exceptions, I would like to define MyAppParent Actor and have all my actors under this Actor. Is it possible to do this using AKKA. In Realtime I need to sending messages directly to the child Actors mailbox under MyAppParentActor and not through the parent Actor. Any pointers on how to do this if it is possible with AKKA.

Thanks, cabear

Upvotes: 1

Views: 300

Answers (1)

Mark
Mark

Reputation: 863

Just started looking into Akka. From my understanding (correct me I am wrong) to your question. Akka has a hierarchy. Root guardian -> user guardian -> your actor hierarchy. So if you want to create a top level actor (children of user guardian).

ActorSystem system = ActorSystem.create("mySystem");
ActorRef ref = system.actorOf(Props.create(TopLevelActor.class);

Now if you want to create a child actor for the above created top level actor. Instead of 'system' use the actors context. eg

getContext().actorOf(Props.create(ChildOfTopLevel.class)).tell(
                    new Message(0, 200000), getSelf());

You can use the tell method like above to instruct a top level actor to send messages to its child that you just created. Also the message won't go directly to child it will go the mailbox.

So I think you just have to look into context and tell.

You should read the official documentation (http://akka.io/docs/). It's pretty detailed. Also, I am still on the third chapter of the documentation so correct me if I got this wrong.

Upvotes: 1

Related Questions