Hi,
On Tue, Aug 12, 2014 at 7:37 AM, soumya sengupta <[email protected]> wrote: > I have a parent Actor class called MainActor and a child actor called > HelloLocalActor > ------------------------------------------------------------ > ---------------------------------------- > public class MainActor extends UntypedActor{ > ActorRef actorRef ; > @Override > public void onReceive( Object message ) throws Exception > { > if( message instanceof MyMessage ) > { > actorRef = getSender(); > System.out.println("In Main Actor"); > getContext().actorOf(Props.create(HelloLocalActor.class), > "HelloLocalActor").tell(message, self()); > > } > else if(message instanceof MyLocalMessage){ > System.out.println("Inside Main Actor"); > actorRef.tell(message, self()); > } > else > { > unhandled( message ); > } > } > } > > ------------------------------------------------------------ > ---------------------------------------------------------- > > public class HelloLocalActor extends UntypedActor > { > @Override > public void onReceive( Object message ) throws Exception > { > if( message instanceof MyMessage ) > { > System.out.println("Inside Hello Local Actor.."); > MyMessage myMessage = ( MyMessage )message; > MyLocalMessage myLocalMessage = new MyLocalMessage(); > myLocalMessage.setMessage( "Local Hello, " + > myMessage.getMessage() ); > getSender().tell( myLocalMessage, getSelf() ); > getContext().stop(getSelf()); > } > else > { > unhandled( message ); > } > } > } > ------------------------------------------------------------ > -------------------------------------------- > > In the HelloLocalActor's onReceive() method, I am calling the > "getContext().stop(getSelf());" method. > If I don't do so, I sometimes get the "InvalidActorNameException: actor > name [HelloLocalActor] is not unique!" error. > > My questions are ? > 1) Is it okay to call "getContext().stop(getSelf());" method ? > yes In the parent actor you must also use getContext().watch of the child actor and only after you have received the Terminated message the name "HelloLocalActor" is free to use. Otherwise you must use unique names for each created child actor. > 2) Will it have any adverse effect on the application? > no, it stops the actor, as intended 3) It really necessary to call the stop() after the child worker has > stopped execution? > Otherwise you will have a memory leak. The actor instance is still referenced, and not garbage collected. It can't know that it has stopped execution, it is ready to receive next message. Regards, Patrik > -- > >>>>>>>>>> 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- Patrik Nordwall Typesafe <http://typesafe.com/> - Reactive apps on the JVM Twitter: @patriknw -- >>>>>>>>>> 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
