Question

I have a play framework 2 that is connected to a remote Akka cluster system both systems are in java. I have a data struture that is wrapped in a class and I have implemented serializable on the wrapper class. I want to use the data strauture for remote computation but any time I try to send the wrapper class to the remote Akka system I get an error .

Below are the code snippets.

this is the wrapper class

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;
             }          
}

this is the Actor class that sends the object

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");
    }

}

this is the Akka actor the receives the class

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);}
  }  
}

this is the error message from my 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)
]

I have alos implemented the Coordinate class in the Remote Akka system as well. Any suggestion or help will be appreciated. thanks

Was it helpful?

Solution

You don't have to implement the Coordinate class twice. You should have a module containing all your models class (Coordinate and so on), and make the other two Akka projects depending on this first one.

You should have this kind of project/module dependency:

module containing Coordinate class (Maven Project)
   |
   ---- Local Actor (Play project)
   |
   ---- Remote Actor (Maven Project)

OTHER TIPS

Obviously your master actor does not have controllers.Coordinates in it's classpath. Another answer suggested code reusability, but that is not the root cause; neither does it make sense in some cases (you could have different operations in local and master). How is your master actor built? What does it's classpath look like? Just add the class to master project and you should be fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top