gpt4 book ai didi

java - Akka future 与 Play 框架

转载 作者:行者123 更新时间:2023-12-01 16:32:51 24 4
gpt4 key购买 nike

我正在尝试使用 Akka future 和 play 框架来连接到远程 akka 系统。运行系统后,akka future 会警告我还剩下一个参数。

代码如下:

这是[外行 Controller 代码:

ackage controllers;

import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import play.*;
import play.mvc.*;

import views.html.*;

public class Application extends Controller {



public static Result index() throws InterruptedException {

System.out.println(" Local Node Called0");


ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));
ActorRef localNode = csystem.actorOf(new Props(LocalNode.class));

System.out.println(" Local Node Called1");
localNode.tell("Hello");
System.out.println(" Local Node Called2");

Thread.sleep(5000);
csystem.shutdown();
return ok(index.render("I am OK"));
}
}

这是play框架本地actor节点

封装 Controller ;

导入akka.actor。;导入 akka.dispatch.Await;导入 akka.dispatch.Future;导入 akka.event.Logging;导入 akka.event.LoggingAdapter;导入 akka.util.Duration;导入 akka.util.Timeout;导入 akka.pattern.;

公共(public)类 LocalNode 扩展了 UntypedActor {

    LoggingAdapter log = Logging.getLogger(getContext().system(), this);
Timeout timeout = new Timeout(Duration.parse("20 seconds"));

ActorRef masterActor;

public void preStart()
{
/* Get reference to Master Node*/
masterActor =

getContext().actorFor("akka://MasterNode@127.0.0.1:2552/user/masterActor");
}

@Override
public void onReceive(Object message) throws Exception {
System.out.println(" Future called ");

Future<Object> future = Patterns.ask(masterActor , message.toString(), timeout);

String result = (String) Await.result(future, timeout.duration());

log.info("Messagefrom Server", result.toString());
}
}

这是远程akka系统master nide

package Rubine_Cluster;

import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.kernel.Bootable;

/**
* Hello world!
*
*/
public class MasterNode implements Bootable
{
final ActorSystem system;

public MasterNode() {
system = ActorSystem.create("MasterNode", ConfigFactory.load()
.getConfig("masterNode"));
ActorRef masterActor = system.actorOf(new Props(MasterActor.class),"masterActor");
System.out.println(" Master Node is called ");
}

public void startup() {

}

public void shutdown() {
system.shutdown();
}
}

这是akka远程系统MasterActor

package Rubine_Cluster;

import akka.actor.*;


public class MasterActor extends UntypedActor {

@Override
public void onReceive(Object message) throws Exception {


if (message instanceof String) {
// Get reference to the message sender and reply back
getSender().tell(message + " got something");
}
}
}

这是来自 Play Framework 的消息

[INFO] [09/30/2012 16:47:25.669] [Application-akka.actor.default-dispatcher-1] [
akka://Application/user/$a] Messagefrom Server WARNING arguments left: 1

需要帮助,因为我应该在作业截止日期前完成

感谢大家

最佳答案

“剩余参数:1”警告是由以下行引起的:

log.info("Messagefrom Server", result.toString())

您正在将未使用的参数传递给记录器。应该是这样的:

log.info("Messagefrom Server {}", result.toString())

关于java - Akka future 与 Play 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12662762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com