Actor Life Cycle
The following is the life cycle of an actor, including any hook methods.
Starting
- Actor initializes.
- PreStart() hook method is called.
Receiving Messages
- Actor is up and now able to process messages.
Stopping
- Actor cleans up.
- PostStop() hook method is called, if actor is terminating.
- PreRestart() hook method is called, if actor is restarting.
Terminated
- Actor is dead.
Restarting
- Actor is going to restart.
- PostRestart() hook method is called.
Hook Methods
PreStart()
- Called before actor instance receives its first message.
- Custom intialization code, preparing actor to start receiving messages.
- Opening/creating files, system handles, etc.
PostStop()
- Called after actor has been stopped and not receiving messages anymore.
- Custom cleanup code.
- Release system resources/handles such as file system.
PreRestart()
- Called before actor begins restarting.
- Allows code to do something with current message/exception.
- Save current message for reprocessing when actor restarts.
PostRestart()
- Called after PreRestart() and before PreStart()
- Allows code to do something with exception
- Additional custom diagnostic/logging

How many times have you felt like you are just re-inventing the wheel as you code? You have to look up ISO standards, ask Google questions to find your answer and sometimes you just have to create something from scratch. I felt this way when I needed to add countries, states and/or provinces to my current project.