Akka中的硬重启指令? [英] Hard restart directive in Akka?

查看:77
本文介绍了Akka中的硬重启指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种优雅的方法来对actor进行硬重启-即清除邮箱以及内部状态?

Is there an elegant way of doing a hard restart of an actor - i.e. clearing out the mailbox along with internal state?

我知道可以通过调用来完成 context.stop 并根据 DeathWatch / Terminated 消息重新初始化,但这有点笨拙。

I know it can be done by calling context.stop and reinitializing upon the DeathWatch / Terminated message, but that's a bit clunky.

推荐答案

不,清除邮箱正是通过终止actor来完成的。如果要在没有终止语义的情况下进行尝试,那么如何确保清除了所有内容?新消息可能会随时出现。

No, clearing out the mailbox is exactly what is done by terminating the actor. If you were to try that without the termination semantics, how could you ever be sure that you cleared everything? New messages could come in at any point in time.

因此,要进行硬重启,请

So, to do that hard restart you


  • 从主管策略中返回 Stop 指令

  • 然后在收到参与者的已终止消息。

  • return the Stop directive from the supervisor strategy
  • then create a new child once you receive that actor’s Terminated message.

这篇关于Akka中的硬重启指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆