2017-04-19 86 views
0

我有一个演员与接收方法:akka和testkit。不能让孩子演员

def receive: Actor.Receive = { 
    case Tick => 
     val child = context.system.actorOf(...) // create actor 
     context.watch(child) 
     child ! something 

    case AskRunningJobs => 
     log.info(s"My children: ${context.children.toList.length}") 
     log.info(s"My children: ${context.children.toList.map(_.path.toSerializationFormat).mkString(" ||| ")}") 
     sender ! RunningJobs(context.children.toList.length) 

    case unknown => 
     log.warning(s"unknown message: $unknown") 
    } 

我有详细的日志输出,我可以清楚地看到所创建的孩子,他们都在运行。但是

context.children.toList.length 

总是零。为什么? 我正在使用TestKit运行我的演员。

回答

2

通过建立儿童这样

val child = context.system.actorOf(...) // create actor 

你做监护人的创建者子女(即你失去的情况下)。只有你的顶级演员应该以这种方式创建。

为了让他们的演员的孩子,你需要使用

val child = context.actorOf(...) // create actor 

代替。有关演员创作的更多信息,请参见docs

+0

啊,谢谢。我错过了... – Sergey