Skip to content

Instantly share code, notes, and snippets.

@nraychaudhuri
Last active August 29, 2015 14:04
Show Gist options
  • Save nraychaudhuri/3fb36ac979a3f0274249 to your computer and use it in GitHub Desktop.
Save nraychaudhuri/3fb36ac979a3f0274249 to your computer and use it in GitHub Desktop.

The default SupervisorStrategy in Akka

At times it's hard to remember all the details of restarting a faulty actor. So lets take a look at a simple example:

/user/grand-parent/parent/child

Here we have a Child actor with one Parent and one GrandParent actor.

The default SupervisorStrategy will decide to Restart an actor after any NotFatal throwable except for ActorInitializationException, DeathPactException or ActorKilledException in which case the decision will be Stop.

When Parent actor fails ...

What happens... GrandParent Parent Child
`preStart` Not called Indirectly called on the new instance from `postRestart` Not called
`postStop` Not called Indirectly called on the old instance from `preRestart` Called after the actor is stopped
`preRestart` Not called Called on the old instance; stops all child actors and calls `postStop` by default Not called
`postReStart` Not called Called on the new instance; calls `preStart` by default Not called
What happens to mailbox? N.A. Still available Lost
What happens to the current message? N.A. Accessible in `preRestart()` N.A.
What happens to the actor's state? N.A. Reset [1] Lost

Here is an nice example of supervisor stratgey in action

[1] You can use Akka Persistence to restore the internal state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment