Scala 中的 Actor 引用
Actor references in scala
/user/master/"+startID
和 /user/master/*
有什么区别?
我假设 * 表示 StartRouteProcess
消息将发送给所有参与者。这个对吗?
然而,/user/master/"+startID
将 Task
消息发送给具有给定 startID
的参与者
case JoinNode =>
val startID = Nodelist(Random.nextInt(numJoined))
context.system.actorSelection("/user/master/" + startID) ! Task("Join", startID, Nodelist(numJoined), -1)
case BeginRouting =>
println("Node Join Finished.\n")
println("Routing started.")
context.system.actorSelection("/user/master/*") ! StartRouteProcess
根据 akka 文档 https://doc.akka.io/docs/akka/2.5/general/addressing.html#querying-the-logical-actor-hierarchy:
Selections may be formulated using the ActorSystem.actorSelection and ActorContext.actorSelection methods and do support sending messages:
context.actorSelection("../*") ! msg
will send msg to all siblings including the current actor.
所以你是对的。
/user/master/"+startID
和 /user/master/*
有什么区别?
我假设 * 表示 StartRouteProcess
消息将发送给所有参与者。这个对吗?
然而,/user/master/"+startID
将 Task
消息发送给具有给定 startID
case JoinNode =>
val startID = Nodelist(Random.nextInt(numJoined))
context.system.actorSelection("/user/master/" + startID) ! Task("Join", startID, Nodelist(numJoined), -1)
case BeginRouting =>
println("Node Join Finished.\n")
println("Routing started.")
context.system.actorSelection("/user/master/*") ! StartRouteProcess
根据 akka 文档 https://doc.akka.io/docs/akka/2.5/general/addressing.html#querying-the-logical-actor-hierarchy:
Selections may be formulated using the ActorSystem.actorSelection and ActorContext.actorSelection methods and do support sending messages:
context.actorSelection("../*") ! msg
will send msg to all siblings including the current actor.
所以你是对的。