2014-11-03 52 views
8

我正在与Akka合作,我们仍然彼此了解。Akka调度员继承权

我的方案是:我选择了一个非默认调度员,负责管理(监督)并创建子actor来完成这项工作。

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

我知道你可以显式地指定一个不同的调度器,用于在配置中指定的父actor的子actor。

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

    "/my-parent-actor/*" { 
    dispatcher = dispatcher-for-children 
    } 
} 

我的问题是关于如果指定父演员调度,没有明确指定为孩子的演员调度员,有没有继承父母的演员的孩子。

回答

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 _ => 
    } 
} 

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

I am the supervisor, my dispatcher is: PinnedDispatcher[my-custom-dispatcher] 
I am the child, my dispatcher is: Dispatcher[akka.actor.default-dispatcher] 
+0

感谢堆。很好的答案!在Akka的这个每个其他阶段都非常好,可以将我所看到的与具有相同结果的其他人相关联。再次感谢!! – neurozen 2014-11-05 04:17:48