Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hard restart directive in Akka?

Tags:

scala

akka

actor

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.

like image 493
Kevin Li Avatar asked Mar 04 '13 23:03

Kevin Li


People also ask

What is supervision strategy in Akka?

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.

What is dispatcher in Akka?

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.

How do you stop Akka actor?

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.

What happens to an actor's reference when an actor is restarted as a result of a crash?

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.


1 Answers

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

  • return the Stop directive from the supervisor strategy
  • then create a new child once you receive that actor’s Terminated message.
like image 115
Roland Kuhn Avatar answered Sep 22 '22 06:09

Roland Kuhn