顶级Akka演员升级和关机挂钩 [英] Top-level Akka actor escalation and shutdown hooking

查看:229
本文介绍了顶级Akka演员升级和关机挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Akka系统中,有一个顶级(root)演员, Initializer ,所有其他演员都来自。还有一个演员 Destroyer ,负责在收到 Destroy 消息时正常关闭系统。有几种情况下,演员将向 Destroyer 发送 Destroy ,但这些条件并不重要

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.

我现在想在 Initializer中实现功能 SupervisorStrategy 如果它无法处理其中一个chidren抛出的故障/异常,它会将其解释为停止世界类型事件,并将系统正常关闭。

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.

我的膝盖反应是让 Initializer 升级失败,但我不知道当最顶级的演员升级时会发生什么。如果有一种方法可以通过某种方式调用 Desroyer ,但是不知道如何连接所有这些。任何想法?

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?

推荐答案

我在这里回答了一个类似的问题:如何升级Akka最顶级的主管?

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"

然后在您的初始化程序中,您应该升级任何你想要对系统致命的例外。然后,初始化程序将被停止。您可以从 Destroyer 中查看 Initializer ,并对终止的事件,或者如果要遵守自定义销毁消息,请将 Destroy 发送到 Destroyer postStop() Initializer

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.

这篇关于顶级Akka演员升级和关机挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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