Hi,

Can you clarify a bit what you're trying to do?
Are the children and grandchildren supposed to be Actors? What's a Node?

Generally speaking, if you want actor1 to be actor2's parent, then actor1 
has to be the one creating actor2. Even then, all actor1 will have is an 
ActorRef, not a reference to the actual actor. This is an important 
distinction, because it means there is no way to call a "getChildren" 
method on a child actor to obtain the grandchildren. Instead, you would 
have to send a message to that child, and wait for it to respond.

To try and answer your specific questions:
1. There is no built-in way of telling when an actor is initialized (and, 
by extension, when a group of actors is initialized). In most cases, this 
shouldn't matter to you - once you call context.actorOf and obtain an 
ActorRef you can start using it (sending it messages) without having to 
wait. Once the actor is initialized, it'll start handling those messages.

2. You can either save them (in a Map, List, whatever) or use 
context.getChildren. Again, though, note that these are ActorRefs and not 
the actual actor objects.

3. This is easier - since no one has access to an actor's state, you can 
change it freely as long as you're in the actor's receive method (or it's 
somewhere in your call-stack). You have to be careful with callbacks, 
futures, etc. that run on different threads, though.

HTH,
Tal


On Thursday, October 19, 2017 at 3:48:30 PM UTC+3, Hsnamed wrote:
>
> Hello, i trying to build actor system as N-levels tree with mutable 
> state/data . 
>
>
> public class RootActor extends AbstractActor implements Loggable {
>  String name;
>  Root data;
>
>  public static Props props(String name, Root data, List<Node<?>> children) {
>  return Props.create(RootActor.class, () -> new RootActor(name, data, 
> children));
>  }
>
>  public RootActor(String name, Root data, List<Node<?>> childs) {
>  this.name = name;
>  this.data = data;
>  spreadChilds(childs);
>  }
>
>  @Override
>  public Receive createReceive() {
>            return receiveBuilder().build();
>  }
>
>  private void spreadChilds(List<Node<?>> childs) {
>  childs.forEach( node -> {
>          Data obj = ((Node<Data>)node).getData();
>          List<Node<?>> grandchilds = node.getChildren();
>          getContext().actorOf(ChildActor.props(obj.getName(), obj, 
> grandchilds), obj.getName());
>  });
>  }
> }
>
>
> 1. What is the right way to initialize list of child actors and 
> grandchildren , does the supervisor strategy helps me to know when actor 
> tree initialization completed ?
> 2. Do i need to store child actors references in their parents ?
> 3. Are there right ways to initialize actors with mutable state/values ?
>
> Thank you for advices.
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to