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
.
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