0

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

我下载了选项 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.javain 函数输出的相关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());

它现在正在工作,但我认为这不是正确的解决方案,它只是一种避免真正问题的解决方法。


4

1 回答 1

0

由于路径问题,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 / 其他 IDE 并且没有正确配置路径,请将其放置在 target/classes/ 或 target/ 或 bin/ 或它们放置已编译类的位置。

于 2016-01-05T12:11:39.443 回答