Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Akka在SIGTERM上自定义关机?_Akka - Fatal编程技术网

如何使用Akka在SIGTERM上自定义关机?

如何使用Akka在SIGTERM上自定义关机?,akka,Akka,默认情况下,Akka在收到SIGTERM时关闭actor系统。在关闭akka系统之前,如何覆盖此行为以执行自定义关闭逻辑?我已经在actors中实现了这个逻辑,使用了特殊的优雅停止消息-我只需要在收到SIGTERM时调用该逻辑 还是必须使用其他方法关闭应用程序?这也是一个选项。您可以像这样使用sys.shutdownhookshread: def main(args: Array[String]) { ... initialization code ... sys.shutdownHoo

默认情况下,Akka在收到
SIGTERM
时关闭actor系统。在关闭akka系统之前,如何覆盖此行为以执行自定义关闭逻辑?我已经在actors中实现了这个逻辑,使用了特殊的优雅停止消息-我只需要在收到
SIGTERM
时调用该逻辑


还是必须使用其他方法关闭应用程序?这也是一个选项。

您可以像这样使用
sys.shutdownhookshread

def main(args: Array[String]) {
  ... initialization code ...
  sys.shutdownHookThread {
    println "Shutting down ..."
    shutdownHandler ! DoSomething
  }
}
这是否适合:

抽象定义 寄存器终止(代码:Runnable):单位 注册一个代码块(回调),以便在发出ActorSystem.shutdown并且此actor系统中的所有actor都已停止后运行。通过多次调用此方法,可以注册多个代码块。回调将按与注册相反的顺序运行,即先运行最后一次注册。 抛出异常 A. 如果系统已关闭或已启动关闭,则拒绝执行异常。 抽象定义 寄存器终止[T](代码:⇒ T) :单位 注册一个代码块(回调),以便在发出ActorSystem.shutdown并且此actor系统中的所有actor都已停止后运行。通过多次调用此方法,可以注册多个代码块。回调将按与注册相反的顺序运行,即先运行最后一次注册。 抛出异常 A. 如果系统已关闭或已启动关闭,则拒绝执行异常。
在actor系统关闭之前,它肯定会运行吗?我没有看到任何文档明确说明这一点,但它对我们有效。阅读源代码和Javadoc,似乎无法保证关闭挂钩的运行顺序,因此,不,它不会总是在正确的时间运行。例如,在Java的一个版本中它可能工作,但在另一个版本中,顺序可能会改变,它可能不工作。或者,关闭钩子可能同时运行。问题是,到那时,所有参与者都将被关闭,因此我认为它们内部的数据将不再可用。六羟甲基三聚氰胺六甲醚。。。我想我可以将数据转储到postStop中actor系统“外部”的一个特殊对象,然后在终止回调中从那里提取数据,但这有点尴尬。我认为,将启动和停止应用程序的脚本更改为使用SIGTERM以外的其他东西(例如Linux fifo)将是最简单的方法。 abstract def registerOnTermination(code: Runnable): Unit Register a block of code (callback) to run after ActorSystem.shutdown has been issued and all actors in this actor system have been stopped. Multiple code blocks may be registered by calling this method multiple times. The callbacks will be run sequentially in reverse order of registration, i.e. last registration is run first. Exceptions thrown a RejectedExecutionException if the System has already shut down or if shutdown has been initiated. abstract def registerOnTermination[T](code: ⇒ T): Unit Register a block of code (callback) to run after ActorSystem.shutdown has been issued and all actors in this actor system have been stopped. Multiple code blocks may be registered by calling this method multiple times. The callbacks will be run sequentially in reverse order of registration, i.e. last registration is run first. Exceptions thrown a RejectedExecutionException if the System has already shut down or if shutdown has been initiated.