Reputation: 19378
I have three actors. Actor A spawns actor B and actor C for performing various tasks and does not depend upon the result of actor B and C
Actors B and C are created in the following way:
ActorRef actorB = this.getContext().actorOf(Props.create(ActorB.class, t));
actorB.tell(new msg, getSelf());
ActorRef actorC = this.getContext().actorOf(Props.create(ActorC.class, t));
actorC.tell(new anothermsg, getSelf());
How do I ensure that this hierarchy is torn down after the task is complete by each actor?
Do I send an explicit poisonPill message to both actors B and C? Or will this be taken care of ?
Upvotes: 0
Views: 41
Reputation: 9023
If you want B and C to stop independently of A, then the easiest way would be for them to call context stop self
after their job is complete. A can be notified of this events by registering to them via - e.g. - context watch b
.
If, otherwise, you want the whole hierarchy to stop at the same time - i.e. when A terminates - then you only need to stop A, as all its children will be automatically stopped as a consequence.
For a more comprehensive coverage of the topic, see here.
Upvotes: 1