2

我有一个连接到远程 Akka 集群系统的游戏框架 2,两个系统都在 java 中。我有一个包装在一个类中的数据结构,并且我已经在包装类上实现了可序列化。我想使用数据结构进行远程计算,但是每当我尝试将包装类发送到远程 Akka 系统时,都会出现错误。

下面是代码片段。

这是包装类

package controllers;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

public class Coordinates implements Serializable{


    String className = null;
    Map <String,ArrayList<Object>> jMap = null;
    boolean train = false;

    public Coordinates() { train = true;}

    public Coordinates (String className)
    {   
        this.className = className;     
    }

    public Coordinates (Map <String,ArrayList<Object>> jMap , boolean b)
    {           

        this.jsonMap = jMap;    
        train = b;
             }          
}

这是发送对象的 Actor 类

package controllers;

import akka.actor.ActorRef;
import akka.actor.UntypedActor;

public class LocalActor extends UntypedActor {

     ActorRef masterActor;
    @Override
    public void onReceive(Object arg) throws Exception {
         if(arg instanceof Coordinates)
         {   Coordinates msg = (Coordinates) arg ;
             masterActor.tell(msg , getSelf());
         }      
    }


    public void preStart()
    {
      masterActor = getContext().actorFor("akka://MasterNode@127.0.0.1:2552/user/masterActor");
    }

}

这是接收课程的 Akka 演员

package Rubine_Cluster;

import java.io.Serializable;

import akka.actor.*;


public class MasterActor extends UntypedActor implements Serializable{

    public MasterActor(){System.out.println(" the masteractor has been started ");}

    @Override
    public void onReceive(Object message) throws Exception {
        System.out.print(" this is from before me to you  "+message.toString());

         if(message instanceof Coordinates)
         {   Coordinates msg = (Coordinates) message;

             try { System.out.print(" this is from message  " + msg.jsonMap.toString());
                  getSender().tell( 1234 , getSelf());
                } catch (Exception e) {
                  getSender().tell(new akka.actor.Status.Failure(e), getSelf());
                  throw e;
                }

    }
         else{ unhandled(message);}
  }  
}

这是来自我的 Eclipse IDE 的错误消息

[INFO] [10/02/2012 02:58:35.606] [main] [ActorSystem(MasterNode)] REMOTE: RemoteServerStarted@akka://MasterNode@127.0.0.1:2552
 Master Node is called 
 the masteractor has been started 
[INFO] [10/02/2012 02:59:28.223] [MasterNode-7] [ActorSystem(MasterNode)] REMOTE: RemoteClientStarted@akka://LocalNode@127.0.0.1:63305
[ERROR] [10/02/2012 02:59:28.334] [MasterNode-7] [ActorSystem(MasterNode)] REMOTE: RemoteServerError@akka://MasterNode@127.0.0.1:2552] Error[java.lang.ClassNotFoundException:controllers.Coordinates
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at java.io.ObjectInputStream.resolveClass(Unknown Source)
    at akka.util.ClassLoaderObjectInputStream.resolveClass(ClassLoaderObjectInputStream.scala:12)
    at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
    at java.io.ObjectInputStream.readClassDesc(Unknown Source)
    at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
    at akka.serialization.JavaSerializer$$anonfun$1.apply(Serializer.scala:121)
    at scala.util.DynamicVariable.withValue(DynamicVariable.scala:57)
    at akka.serialization.JavaSerializer.fromBinary(Serializer.scala:121)
    at akka.serialization.Serialization.deserialize(Serialization.scala:73)
    at akka.remote.MessageSerializer$.deserialize(MessageSerializer.scala:22)
    at akka.remote.RemoteMessage.payload(RemoteTransport.scala:210)
    at akka.remote.RemoteMarshallingOps$class.receiveMessage(RemoteTransport.scala:276)
    at akka.remote.netty.NettyRemoteTransport.receiveMessage(NettyRemoteSupport.scala:30)
    at akka.remote.netty.RemoteServerHandler.messageReceived(Server.scala:182)
    at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:75)
    at akka.remote.netty.RemoteServerHandler.handleUpstream(Server.scala:154)
    at org.jboss.netty.channel.StaticChannelPipeline.sendUpstream(StaticChannelPipeline.java:366)
    at org.jboss.netty.channel.StaticChannelPipeline$StaticChannelHandlerContext.sendUpstream(StaticChannelPipeline.java:528)
    at org.jboss.netty.handler.execution.ChannelUpstreamEventRunnable.run(ChannelUpstreamEventRunnable.java:44)
    at org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor$ChildExecutor.run(OrderedMemoryAwareThreadPoolExecutor.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
]

我也在 Remote Akka 系统中实现了 Coordinate 类。任何建议或帮助将不胜感激。谢谢

4

2 回答 2

1

您不必两次实现 Coordinate 类。您应该有一个包含所有模型类(坐标等)的模块,并根据第一个创建其他两个 Akka 项目。

你应该有这种项目/模块依赖:

module containing Coordinate class (Maven Project)
   |
   ---- Local Actor (Play project)
   |
   ---- Remote Actor (Maven Project)
于 2012-10-02T06:34:53.570 回答
0

显然,您的主演员在其类路径中没有控制器。坐标。另一个答案建议代码可重用性,但这不是根本原因;在某些情况下也没有意义(您可以在本地和主控中进行不同的操作)。你的男主角是怎么炼成的?它的类路径是什么样的?只需将类添加到主项目,你应该没问题。

于 2012-10-10T20:11:07.120 回答