Akka学习笔记04--Actor生命周期

来源:互联网 发布:淘宝助手怎么上细节图 编辑:程序博客网 时间:2024/06/09 15:49

actor的生命周期大致上可分为下面三种阶段:

•初始化和启动

•通过执行特定的行为来接收和处理消息。

•当接收到终止命令时,停止。

此外,当actor的生命周期改变时,我们可以运用一些额外的可选方法(hooks)控制这些状态:

•重写preStart()和postStop()方法:可以初始化/清空任何actor资源。

•重写preRestart() 和 postRestart() :当出现异常或者上层actor重启当前actor时,用于控制状态。


原文:

**********************************************************************************************************************

An actor's lifecycle broadly consists of three phases as follows:

• Actor is initialized and started

• Actor receives and processes messages by executing a specific behavior

• Actor stops itself when it receives a termination message

Additionally, an Akka actor has additional, optional hooks that can be used to manage the state where it experiences a lifecycle change. The additional hooks are as follows:

• preStart() and postStop() can be implemented to initialize/clean any resources used by the actor to process the messages

• preRestart() and postRestart() allow the actor to manage the state in case an exception has been raised and Supervisor actor restarts the actor



tips:翻译于《Akka.Essentials》第三章,可能会有出入。附上原文。

1 0