Hard restart directive in Akka?

Is there an elegant way to make an actor hard restart, that is, to clear the mailbox along with the internal state?

I know this can be done by calling context.stop and reinitializing the DeathWatch / Terminated message, but it's a bit awkward.

+6
source share
1 answer

No, cleaning the mailbox is exactly what is done by completing the actor. If you tried this without the semantics of completion, how would you be sure that you cleared everything? New messages may appear at any time.

So, to do this hard restart, you

  • returns a Stop directive from a supervisor strategy
  • then create a new child after receiving this Terminated message.
+5
source

All Articles