Actor lifecycle monitoring

We saw the typed actor being defined and created, methods getting invoked, and how to stop the actors. In the case of untyped actors we saw support for the preStart() and postStop() methods where any resource initialization and subsequent cleaning could be handled.

So, in the case of typed actors, additional hooks can be implemented by making the implementation class implement additional interfaces. These interfaces can be overridden to initialize resources on actor start and clean up resources on actor stop.

Lifecycle callbacks

Typed actors can implement the TypedActor.PreStart and TypedActor.PostStop interfaces to add the additional hooks into the code.


public class Calculator implementsCalculatorInt, PreStart, ...

Get Akka Essentials now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.