我正在使用scala akka actor模型。我有一位父母演員創建n個孩子演員。兒童演員首先彼此交談,然後向主演員報告答案。但是我無法爲報告部分工作。代碼結構如下:如何在scala akka中找到父母演員
class Master(n:Int) extends Actor{
val system =ActorSystem("mysystem")
for(i <- 1 to n){
val child=system.actorOf(Props(new Node),name=i.toString)
}
... code let child actor talk with each other ...
def receive={
case _=>"received"
}
}
class Node extends Actor{
def receive={
case => ... some code talking with each other...
var master=context.actorSelection("../Master")
master ! "talk back to master"
}
}
def main() {
val Master=system.actorOf(Props(new Master(10)),name="Master")
}
此行:'val child = system.actorOf(Props(new Node),name = i.toString)'應該是'val child = context.actorOf(Props(new Node),name = i.toString)' –