Dániel Kis
Dániel Kis

Reputation: 2631

Akka: How to remove child actor

I have a parent actor and children. Each child actors controlls a device. I give an uuid as to all child actors when I create them.

Each child actor is created by device configuration, when the configuration is changed, i would like to recreate the actor by:

But it throws an exception: akka.actor.InvalidActorNameException: actor name [6237255c-851b-47d2-ac31-03c7635e6537] is not unique!

I think the gracefulStop code not removes the children actor, my question is: how can I remove the child actor?

I have also tried to remove an actor by a PoisonPill:

actorRef.tell(PoisonPill.getInstance(), getSelf());

Upvotes: 4

Views: 2182

Answers (1)

davidxxx
davidxxx

Reputation: 131396

From the official documentation :

Keep in mind that an actor stopping and its name being deregistered are separate events which happen asynchronously from each other. Therefore it may be that you will find the name still in use after gracefulStop() returned. In order to guarantee proper deregistration, only reuse names from within a supervisor you control and only in response to a Terminated message, i.e. not for top-level actors.

So you should perform the creation of the actor with the recycled name only after the reception of the Terminated message for which a supervisor actor should register to.

Upvotes: 4

Related Questions