May 2017
Intermediate to advanced
414 pages
13h
English
In this preceding recipe, we create an actor, which maintains sum as a state, and we modify its life cycle hooks. We create this actor under the parent supervisor, which handles the ArthimaticException in the child actor. Let's see what happens in life cycle hooks.
When an actor starts, it calls the preStart method, so we see the following output:
"sum in preStart is 1".
When an actor throws an exception, it sends a message to the supervisor, and the supervisor handles the failure by restarting that actor. It clears out the accumulated state of the actor, and creates a fresh new actor, means, it then restores the last value assigned to the state of old actor to the preRestart value.
After that postRestart method is called, ...
Read now
Unlock full access