阿卡调度员的继承权

neu*_*zen 8 inheritance scala parent-child dispatcher akka

我正在和Akka一起工作,我们仍然要相互了解.

我的方案是:我为主管(父)演员选择了一个非默认调度员,他的角色是管理(监督)并创建子演员来完成工作.

问题:儿童演员是否继承了父母的演员

我知道您可以为配置中指定的父actor的子actor 明确指定一个不同的调度程序.

akka.actor.deployment {
  /my-parent-actor {
    dispatcher = dispatcher-for-parent
  }

  "/my-parent-actor/*" {
    dispatcher = dispatcher-for-children
  }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果您指定父actor调度程序,而没有明确指定子actor的调度程序,是否继承父项actor的子项.

cmb*_*ter 14

从我所看到的,默认情况下,孩子不会继承父母的主管.我无法在任何地方的文档中明确地找到它,所以我写了一段快速代码来验证我的初始假设:

import com.typesafe.config.ConfigFactory
import akka.actor._

object DispatcherTest extends App{

  val conf = ConfigFactory.parseString("""
      {
          my-custom-dispatcher {
            executor = "thread-pool-executor"
            type = PinnedDispatcher         
          }
      }  
  """)

  val system = ActorSystem("test", conf)
  val supervisor = system.actorOf(Props[MySupervisor].withDispatcher("my-custom-dispatcher"))

}

class MySupervisor extends Actor{
  println(s"I am the supervisor, my dispatcher is: ${context.dispatcher}")
  val child = context.actorOf(Props[MyChild])
  def receive = {
    case _ =>      
  }
}

class MyChild extends Actor{
  println(s"I am the child, my dispatcher is: ${context.dispatcher}")
  def receive = {
    case _ =>
  }
}
Run Code Online (Sandbox Code Playgroud)

如果你运行它,你会看到:

I am the supervisor, my dispatcher is: PinnedDispatcher[my-custom-dispatcher]
I am the child, my dispatcher is: Dispatcher[akka.actor.default-dispatcher]
Run Code Online (Sandbox Code Playgroud)