我正在尝试运行此处教程中提到的示例:
我下载了选项 2 中提到的模板包,并用它配置了一个 Eclipse 项目。
当我Run the Lookup Example
在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
反复。
导致LookupActor.java
in 函数输出的相关onReceive
行是:
calculator = ((ActorIdentity) message).getRef();
if (calculator == null) {
System.out.println("Remote actor not available: " + path);
( pathakka.tcp://CalculatorSystem@127.0.0.1:2552/user/calculator
在类中初始化LookupApplication
并传递给 LookupActor。
所以基本上,calculator = ((ActorIdentity) message).getRef();
总是返回 null,这就是导致这个输出的原因。
到目前为止我试图做的事情:
我试图改变类中的路径变量LookupApplication
:
akka.tcp://CalculatorSystem@127.0.0.1:2552/user/calculator
至
akka.tcp://CalculatorSystem@127.0.0.1:2552/user/CalculatorActor
和行:
system.actorOf(Props.create(CalculatorActor.class),calculator);
至:
system.actorOf(Props.create(CalculatorActor.class), CalculatorActor.class.getSimpleName());
正如我从这里提到的那样理解。
但它没有帮助,它总是返回 null 。我认为这是一个问题,因为教程说输出应该不同。
将不胜感激任何帮助
编辑:
我在类中编辑了“ onRecieve
”方法,如下所示:LookupActor
@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;
}
并更新了方法“ sendIdentifyRequest
”,而不是:
getContext().actorSelection(path).tell(new Identify(path), getSelf());
就是现在
getContext().actorSelection(path).tell(msg.GREET, getSelf());
它现在正在工作,但我认为这不是正确的解决方案,它只是一种避免真正问题的解决方法。