我有以下阿卡演员:
public class MyActor extends AbstractActor {
protected Logger log = LoggerFactory.getLogger(this.getClass());
@Override
public Receive createReceive() {
return receiveBuilder()
.matchAny(message -> {
String myFullName = self().path().toString();
String myName = self().path().name();
ActorRef reincarnatedMe = context().actorFor(self().path().name());
String reincarnatedFullName = reincarnatedMe.path().toString();
String reincarnatedName = reincarnatedMe.path().name();
log.info("myFullName: {}", myFullName);
log.info("myName: {}", myName);
log.info("reincarnatedFullName: {}", reincarnatedFullName);
log.info("reincarnatedName: {}", reincarnatedName);
}).build();
}
}
在运行时,它生成此输出:
05:43:14.617 [MySystem-akka.actor.default-dispatcher-4] INFO myapp.actors.MyActor - myFullName: akka://MySystem/user/MyActor
05:43:14.623 [MySystem-akka.actor.default-dispatcher-4] INFO myapp.actors.MyActor - myName: MyActor
05:43:14.623 [MySystem-akka.actor.default-dispatcher-4] INFO myapp.actors.MyActor - reincarnatedFullName: akka://MySystem/user/MyActor/MyActor
05:43:14.623 [MySystem-akka.actor.default-dispatcher-4] INFO myapp.actors.MyActor - reincarnatedName: MyActor
我的
理解力
是吗?
context().actorFor(...)
不创建
新的
相反,它会找到与您提供的路径/字符串匹配的现有参与者,并返回对其的引用。
但是,在我上面的代码中,
self()
成为
起源
属于
reincarnatedMe
由…证明
myFullName
仅仅是“
MySystem/user/MyActor
“而
reincarnatedFullName
是
MySystem/user/MyActor/MyActor
“……”
我读得对吗?如果是,我如何调用
context().actorfor(…)
(或任何其他方法)使
全名
变得和
转世全名
(这样)
自我()
和
转世
引用同一个演员?如果我读得不对,为什么
全名
不同于
转世全名
?
更新:
public class AnotherActor extends AbstractActor { ... }
// Inside MyActor#createReceive:
ActorSelection anotherActorSel = context().actorSelection("AnotherActor");
anotherActorSel.tell(new SomeMessage(), self());