Akka actorSelection路径快捷方式是否存在?

时间:2019-03-06 19:26:02

标签: java akka

Java 8和Akka 2.5.16在这里。我有以下演员:

public class Guardian extends AbstractActor {
  @Override
  public Receive createReceive() {
    return receiveBuilder()
        .matchAny(message -> {
            // Do stuff in here
        }).build();
  }
}

我这样创建的:

ActorRef guardian = context().actorOf(Props.create(Guardian.class), Guardian.class.getName());
String path = guardian.path().toString();

// Prints: "akka://myapp/user/com.me.myapp.Guardian"
log.info("path = {}", path);

我现在想使用ActorSelection查找这个现有演员:

String pathShortcut = "user/com.me.myappp.Guardian";
ActorSelection guardianSelection = context().actorSelection(pathShortcut);

需要传递完整的(akka://myapp/user/com.me.myapp.Guardian)路径值,还是可以提供如下快捷方式:

// Examples:
String pathShortcut1 = "user/com.me.myappp.Guardian";
String pathShortcut2 = "com.me.myapp.Guardian";
String pathShortcut3 = "Guardian";

换句话说,context().actorSelection(...)是否要求一条标准路径,还是可以采用快捷方式并智能地解析/推断它们?

此外,“路径协议” 总是akka://还是会改变(例如,使用远程actor或其他actor库)?

谢谢!

1 个答案:

答案 0 :(得分:0)

简短的回答是“ ”,您必须提供完整的akka://full/path/to/named/actor/instanceActorSelections