Robin Green
Robin Green

Reputation: 33063

Restart top-level actor in Akka 2.0.x

From the documentation I understood that sending a Kill message to an actor will restart it, but what actually happens is it just stops.

(Is the documentation out of date?)

Upvotes: 0

Views: 504

Answers (2)

Robin Green
Robin Green

Reputation: 33063

Create a new top-level actor which in turn creates the old top-level actor in its preStart method. This will be the supervisor, and the supervisor strategy can be set by putting this code in the new top-level actor:

override val supervisorStrategy = OneForOneStrategy() {
  case _: Exception => Restart
  case _: Throwable => Escalate
}

The Kill message still needs to be sent to what was the old top-level actor.

Upvotes: 1

Endre Varga
Endre Varga

Reputation: 1863

Kill is "A message all Actors will understand, that when processed will make the Actor throw an ActorKilledException, which will trigger supervision.". So if the supervisor strategy of the parent actor of the killed actor is Stop, then it will not be restarted. In akka 2.1.0 you can configure the supervisor strategy of the guardian (i.e.: "/user/") which supervises the top level user-created actors.

Upvotes: 1

Related Questions