Mullefa
Mullefa

Reputation: 1247

akka: querying the children of the guardian actor

In an actor system hierarchy, the documentation states that there is a guardian actor with address /user, and that actors created using system.actorOf() are children of this actor.

Is it possible to query an actor system to get the 'current' children of the guardian actor? And if so, how is this achieved?

Upvotes: 2

Views: 389

Answers (1)

Arne Claassen
Arne Claassen

Reputation: 14404

You can use a wildcard actor selection and the special Identify message to all actors that match that selection. To find the direct children of actor /user do:

system.actorSelection("/user/*") ! Identify(None)

If you want to find all children in the hierarchy, you would have to manually descend the tree by creating a child wildcard actorSelection for each ActorRef receive.

The caveat with all this is, that this identification is asynchronous and you have no way of knowing when all children have identified themselves. The best you can do is to set a time limit after which you assume all children have reported back to you.

Upvotes: 4

Related Questions