Hard restart directive in Akka?

冷暖自知 提交于 2019-12-10 13:15:36

问题


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

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


回答1:


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

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


来源:https://stackoverflow.com/questions/15213032/hard-restart-directive-in-akka

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!