如何使用 Akka Actor 永远 运行 一个守护进程?

How to run a daemon forever using Akka Actor?

ProjectSupervisor
     |
ExistingProcessActor

其中 ExistingProcessActor 将 运行 作为一个永远漫长的 运行ning 工作,如果它因为某些 Exception 而被杀死,ProjectSupervisorrestart

我对此不太确定,所以我在 user-group 上询问,并收到了一个有趣的建议

[Me] def run: Unit = LogReaderDisruptor.main(Array())
is a method that is supposed to run forever, plus it required some setup (that is available on client's machine or test environment)

[Advice here] By that do you mean that the main() is never returning? If so, then you're blocking the Actor and wasting an entire thread. Spawn this off on a dedicated dispatcher instead (see dispatchers and futures docs).

我浏览了文档,但不明白我需要做什么。

是跟风的意思吗?

一头雾水,请指教

您无需使用 Future 即可在专用调度程序中完成工作。这可以通过生成一个 actor 并将该 actor 分配给专用的调度程序来完成。来自 akka 文档的一个简单示例:

val myActor =
  context.actorOf(Props[MyActor].withDispatcher("my-dispatcher"), "myactor1")

http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html

您可以在创建 ExistingProcessActor 时在您的项目主管中执行此操作,将该 actor 放在固定的调度程序上,然后您的监督策略将继续按照您的意愿工作。