本文介绍了Akka主管总经理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为可能存在一个更广泛的使用Akka隐藏在此处的应用程序设计问题,但是我想问一问如何建立一个监督树,其中内核或高层主管可以监督作为其他主管的孩子主管工人?

I reckon there might be a broader question of application design using Akka hidden in here but I'll ask how does one set up a supervision tree where a "kernel" or "top" supervisor might supervise children that are other supervisors which supervisor workers?

推荐答案

您可以从顶层的声明式主管开始

You might start with a declarative supervisor on the top level

 val kernel = Supervisor(
     SupervisorConfig(
         OneForOneStrategy(List(classOf[Exception]), 3, 1000),
         Supervise(
             actorOf[Module1],
             Permanent) ::
         Supervise(
             actorOf[Module2],
             Permanent) ::
         Supervise(
             actorOf[Module3],
             Permanent) ::
         Nil
     )
 )

其中模块1至3代表应用程序体系结构的下一层。每个模块本身都是其所有子行为者的监督者,并且以类似的方式实现

where module 1 to 3 represents the next level of your application architecture. Each module itself is a supervisor for all of its child actors and implemented like for example

class Module1 extends Actor {
   self.faultHandler = OneForOneStrategy(List(classOf[Throwable]), 5, 5000)

   def receive = {
       case Register(actor) =>
       self.link(actor)
   }
}

您可能会使用更适合您的应用程序的内容替换 Register(actor)消息,并且您可能希望跨越进一步的以编程方式创建的主管层,但基本上这是遵循的方法。

You might replace the "Register(actor)" message with something more suitable for your application, and you might want to span a further programmatically created supervisor layer but basically that would be the approach to follow.

您将在或。

这篇关于Akka主管总经理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-29 06:13