Akka Future con Marco de juego
-
11-12-2019 - |
Pregunta
Estoy tratando de usar el futuro Akka con el marco de juego para conectarse a un sistema AKKA remoto .Después de ejecutar el sistema, el futuro AKKA me da una advertencia de que se deja un argumento.
El código está a continuación:
Este es el [CÓDIGO DE CONTROLADOR DE LAICADO: 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"));
}
}
Este es el nodo de actor local del marco de juego
Controladores de paquetes;
Importar Akka.actor. ; Importar akka.dispatch.await; Importar akka.dispatch.future; Importar akka.event.logging; Importar akka.event.loggingadapter; Importar Akka.util.duración; Importar akka.util.timeout; Importar akka.pattern. ;
LocalNode de clase pública extiende a untypetactor {
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());
}
}
Este es el control remoto 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();
}
}
Este es el Masteractor del sistema remoto AKKA
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");
}
}
}
Este es el mensaje del Framewrk de reproducción
[INFO] [09/30/2012 16:47:25.669] [Application-akka.actor.default-dispatcher-1] [
akka://Application/user/$a] Messagefrom Server WARNING arguments left: 1
Se necesita ayuda porque se supone que debe cumplir con la fecha límite de asignación
gracias a todos
Solución
Trate de dar un nombre a su actor en juego:
ActorRef localNode = csystem.actorOf(new Props(LocalNode.class), "localNode");
y también tenga en cuenta que si necesita acceder al sistema AKKA desde el juego, es mejor usar:
ActorSystem csystem = Akka.system();
en lugar de:
ActorSystem csystem = ActorSystem.create("Application", ConfigFactory.load().getConfig("LocalNode"));
Otros consejos
Los "Argumentos a la izquierda: 1" La advertencia se debe a la siguiente línea:
log.info("Messagefrom Server", result.toString())
Estás pasando parámetros no utilizados al registrador.Debería ser esto en lugar de:
log.info("Messagefrom Server {}", result.toString())