你應該能夠做到==
對比只要你有給用戶一個參考監護人。這個簡單的例子表明,平等運作正確。所以,我想你可以某處解決用戶的監護人,並使其全球可用,如果你想要做的比較:
object RootGuardianTest extends App{
val system = ActorSystem("test")
system.actorOf(Props[ChildActor], "child")
}
trait RootComparison{ me:Actor =>
def initCompare{
val sel = context.system.actorSelection("/user")
sel ! Identify()
}
def checkCompare:Receive = {
case ActorIdentity(_, Some(ref)) =>
println(s"I am ${self.path}, and my parent is root: ${context.parent == ref}")
}
}
class ChildActor extends Actor with RootComparison{
val child2 = context.actorOf(Props[Child2Actor], "child2")
initCompare
def receive = checkCompare
}
class Child2Actor extends Actor with RootComparison{
initCompare
def receive = checkCompare
}
我,我只想簡單地檢查父路徑的name
部分,看看它是否是「用戶'如此:
val parentIsUser = context.parent.path.name == "user"