What is supervision?
Describes a dependency relationship between actors, the parent and child releationship. Parent is unique because it has created the child actor, so the parent is responsible for reacting when failures happens in his child.
And parent decides which choice is need to be selected. When a parent receives the failure signal from it’s child, depends on the nature of failure the parent decides from following options:
Resume: Parent starts the child actor keeping it internal state.
Restart: Parent starts the child actor by clearing it’s internal state.
Stop: Stop the child permanently.
Escalate: Escalate the failure by failing itself and propagate failure to its parent.
Akka Actor Life Cycle
It is always important to view an part of supervision hierarchy, which explains the escalate option. Each supervisor should cover with all possible failure cases.
/user: The User Guardian Actor
Actor created using system.actorOf() are children of user guardian actor. Whenever user guardian terminates all user created actors will be terminated too. Top level user created actors are determined by user guardian actor that how they will be supervised. Root Guardian is the supervisor of user guardian.
/root: The Root Guardian
The root guardian actor is the father all actor system. It supervises user guardian actor and system guardian actor.
There are two type of supervision strategies that we follows to supervise any actor:
Example of One-For-One Strategy
What is Monitoring?
Lifecycle Monitoring in Akka is usually referred to as DeathWatch
Monitoring is thus used to tie one actor to another so that it may react to the other actor’s termination, in contrast to supervision which reacts to failure.
Monitoring is particularly useful if a supervisor cannot simply restart its children and has to terminate them, e.g. in case of errors during actor initialization. In that case it should monitor those children and re-create them or schedule itself to retry this at a later time.
Code Repository : Supervision and Monitoring