akka ActorIdentity.getRef()在akka网站示例中返回null

akka ActorIdentity.getRef()在akka网站示例中返回null,akka,actor,akka-remote-actor,Akka,Actor,Akka Remote Actor,我正在尝试运行教程中提到的示例: 我下载了选项2中提到的模板包,并用它配置了一个eclipse项目 当我在eclipse中“运行查找示例”(来自上述教程)时,根据教程,我应该得到如下输出: Started LookupSystem Calculating 74 - 42 Sub result: 74 - 42 = 32 Calculating 15 + 71 Add result: 15 + 71 = 86 但我实际上得到的是以下几行: Remote actor not available:

我正在尝试运行教程中提到的示例:

我下载了选项2中提到的模板包,并用它配置了一个eclipse项目

当我在eclipse中“
运行查找示例”(来自上述教程)时,根据教程,我应该得到如下输出:

Started LookupSystem
Calculating 74 - 42
Sub result: 74 - 42 = 32
Calculating 15 + 71
Add result: 15 + 71 = 86
但我实际上得到的是以下几行:

Remote actor not available: akka.tcp://CalculatorSystem@127.0.0.1:2552/user/calculator
Not ready yet
Not ready yet
Not ready yet 
重复。
函数
onReceive
中的
LookupActor.java
导致此输出的相关行是那些

 calculator = ((ActorIdentity) message).getRef();
 if (calculator == null) {
 System.out.println("Remote actor not available: " + path);
(路径初始化为
akka。tcp://CalculatorSystem@127.0.0.1:2552/user/calculator
LookupApplication
类中,并传递给LookupActor

所以基本上,
calculator=((ActorIdentity)message).getRef();
总是返回null,这就是导致此输出的原因

到目前为止,我一直在努力:

我试图将class
LookupApplication
中的path变量更改为:

 akka.tcp://CalculatorSystem@127.0.0.1:2552/user/calculator  

这句话:

 system.actorOf(Props.create(CalculatorActor.class),calculator); 
致:

 system.actorOf(Props.create(CalculatorActor.class), CalculatorActor.class.getSimpleName());  
正如我所理解的那样

但是它没有帮助,它总是返回null。我认为这是一个问题,因为教程说输出应该不同

非常感谢您的帮助


编辑:
我在
LookupActor
类中编辑了“
onreceive
”方法,如下所示:

  @Override
  public void onReceive(Object message) throws Exception {
     // if (message instanceof ActorIdentity) {
     // calculator = ((ActorIdentity) message).getRef();
    if (message == null) {
       System.out.println("Remote actor not available: " + path);

    } else {
         getContext().watch(calculator);
         getContext().become(active, true);
      }

//      } else if (message instanceof ReceiveTimeout) {
//          sendIdentifyRequest();
//
//        } else {
//             System.out.println("Not ready yet");
//
//          }
}
并创建了一个枚举:

private enum msg{
  GREET;
}
并更新了方法“
sendIdentificationRequest
”,而不是:

getContext().actorSelection(path).tell(new Identify(path), getSelf());
现在是

getContext().actorSelection(path).tell(msg.GREET, getSelf());
它现在正在工作,但我不认为这是正确的解决方案,它只是一个解决办法,可以避免真正的问题



由于路径问题,ConfigFactory无法加载配置,例如:remotelookup.conf、calculator.conf等。由于配置加载失败,ConfigFactory返回使用默认配置akka.actor.LocalActorRefProvider,而不是akka.remote.RemoteActorRefProvider

这行不行:

public static void startRemoteWorkerSystem() {
  ActorSystem.create("CalculatorWorkerSystem",
  ConfigFactory.load(("calculator"))); 
  System.out.println("Started CalculatorWorkerSystem");
}
ConfigFactory.load((“计算器”)

将src/main/resources中的那些配置文件移动到akka可以访问的路径


如果您使用的是Netbean/other IDE,并且没有正确配置路径,请将其放在target/classes/或target/or bin/下,或者放在他们编译的类的位置。

我不熟悉教程代码,但我不确定您的问题到底是什么。“你能详细说明你想回答的问题吗?”DiegoMartinoia我用粗体强调了具体部分,希望它能更好地解释这个问题。问题是我的程序和教程中编写的程序之间的输出不同。导致这种情况的原因是,在方法
onreceive
中,行
calculator=((ActorIdentity)消息).getRef()
返回null;谢谢如果您查看代码,当从LookupActor接收的消息类型既不是Timeout也不是ActorIdentity时,会打印“Not ready yet”(尚未准备就绪)一行。显然有些地方出了问题:我建议您修改分支,它在其中打印“尚未准备就绪”,并打印出接收到的消息类型及其内容,以帮助您进行调试。我不认为这与演员的名字无关(这就是你从“calculator”改为“CalculatorActor”的原因)
public static void startRemoteWorkerSystem() {
  ActorSystem.create("CalculatorWorkerSystem",
  ConfigFactory.load(("calculator"))); 
  System.out.println("Started CalculatorWorkerSystem");
}