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
Leave a Reply