Top-level Akka actor escalation and shutdown hooking

泪湿孤枕 提交于 2019-12-13 01:12:36

问题


In my Akka system there is a top-level ("root") actor, Initializer, from which all other actors come from. There is also an actor, Destroyer, that is responsible for shutting down the system gracefully when it receives a Destroy message. There are several conditions under which an actor would send a Destroy to the Destroyer, but those don't really matter here.

I would now like to implement functionality in Initializer's SupervisorStrategy where, if it can't handle a failure/exception thrown by one of its chidren, it will interpret that as a "stop the world"-type event, and shut the system down gracefully.

My knee jerk reaction is to have Initializer escalate the failure, but I'm not sure what happens when the top-most actor escalates. It would be nice if there was a way for that escalation to somehow invoke the Desroyer, but not sure how to wire that all up. Any ideas?


回答1:


I answered a similar question here: How to escalate top-most supervisors in Akka?

Essentially, in your configuration set:

akka.actor.guardian-supervisor-strategy = "akka.actor.StoppingSupervisorStrategy"

Then in your Initializer you should escalate any exceptions which you want to be fatal for the system. The Initializer will then be stopped. You could watch the Initializer from the Destroyer and react to the Terminated event, or if you want to stick to your custom Destroy message, send Destroy to the Destroyer from postStop() within the Initializer.



来源:https://stackoverflow.com/questions/32136878/top-level-akka-actor-escalation-and-shutdown-hooking

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