ChildSpec with ActorRef appears to create an Actor with the same identity as the original actor.

21 views
Skip to first unread message

John Brinnand

unread,
Sep 21, 2017, 8:59:35 PM9/21/17
to quasar-pulsar-user
Hi,

What is the purpose of using an ActorRef in a child spec? Is it to create a child actor? If so, shouldn't the child actor be a separate instance? For example:

// Note: this actor was create previously and the code to do that is not shown.
ActorRef<?> myParentActorRef = sup.getChild("myParentActor");

// Now lets use this actor to create a new one.

ChildSpec spec = new ChildSpec("myChildActor", ChildMode.TEMPORARY, MAX_RESTARTS, 

                DURATION, TimeUnit.SECONDS, SHUTDOWN_DEADLINE, myParentActorRef);

sup.addChild(spec);


// Lets examine the identity of the child and the parent.

log.info("Instance {} identity hashCode {}", "myParentActor", System.identityHashCode(sup.getChild("myParentActor"))); 

log.info("Instance {} identity hashCode {}", "myChildActor", System.identityHashCode(sup.getChild("myChildActor"))); 


We find the hash code to be exactly the same. And it looks like the the actor name given to the first actor propagates to the child actor. So, if the parent's name is "myParentActor" then the child's name is also "myParentActor". Looking at the code, the name is optional and is not propagated to the child actor. More troubling is the fact that new child actor has the same instance / object identity as the parent. 


I am guessing that I may not be using this as intended, or I am missing something? What it the purpose of creating a new actor with - apparently - the same identity as its parent?


Any help clarifying this would be greatly appreciated.


Thanks,


John


Reply all
Reply to author
Forward
0 new messages