我正在尝试将Akka未来与play框架连接到远程akka系统 。在运行系统之后,akka的未来会给我一个警告,即剩下一个参数。
代码如下:
这是[lay lay code: P
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节点
包控制器;
import akka.actor。; import akka.dispatch.Await; import akka.dispatch.Future; import akka.event.Logging; import akka.event.LoggingAdapter; import akka.util.Duration; import akka.util.Timeout; import akka.pattern。;
公共类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系统主人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 framewrok的消息
[INFO] [09/30/2012 16:47:25.669] [Application-akka.actor.default-dispatcher-1] [
akka://Application/user/$a] Messagefrom Server WARNING arguments left: 1
需要帮助,因为我想要达到作业截止日期
感谢所有
答案 0 :(得分:7)
“参数左:1”警告是由以下行引起的:
log.info("Messagefrom Server", result.toString())
您将未使用的参数传递给记录器。它应该是这样的:
log.info("Messagefrom Server {}", result.toString())
答案 1 :(得分:-1)
尝试在Play中为你的演员命名:
ActorRef localNode = csystem.actorOf(new Props(LocalNode.class), "localNode");
另请注意,如果您需要从Play访问Akka系统,最好使用:
ActorSystem csystem = Akka.system();
而不是:
ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));