Is there an elegant way of doing a hard restart of an actor - i.e. clearing out the mailbox along with internal state?
I know it can be done by calling context.stop
and reinitializing upon the DeathWatch / Terminated
message, but that's a bit clunky.
Depending on the nature of the work to be supervised and the nature of the failure, the supervisor has a choice of the following four options: Resume the subordinate, keeping its accumulated internal state. Restart the subordinate, clearing out its accumulated internal state. Stop the subordinate permanently.
Dispatchers are responsible for scheduling all code that run inside the ActorSystem . Dispatchers are one of the most important parts of Akka.NET, as they control the throughput and time share for each of the actors, giving each one a fair share of resources. By default, all actors share a single Global Dispatcher.
In Akka, you can stop Actors by invoking the stop() method of either ActorContext or ActorSystem class. ActorContext is used to stop child actor and ActorSystem is used to stop top level Actor.
Note that a restart of an actor caused by a failure still means that it is the same actor incarnation, i.e. a restart is not visible for the consumer of the ActorRef.
No, clearing out the mailbox is exactly what is done by terminating the actor. If you were to try that without the termination semantics, how could you ever be sure that you cleared everything? New messages could come in at any point in time.
So, to do that hard restart you
Stop
directive from the supervisor strategyTerminated
message.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With