2017-04-19 83 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