0

I have a play framework that uses the play actor integration to reference and communicate with a remote akka system. Looks like I am not getting the remote referencing right. First the remote akka implements the bootable interface and It has a master node that creates a child actor system.
the play actor system then references the remote system. the code snippets are presented below.

this is the Play framework node that creates the local actor system

 public void connectMaster (final String classname)
 {  
     localActor.tell(classname);

 }

 public  void connectMaster ()
 {  
     //localActor.tell(getByte(new Coordinates()));
 }


 public void connectMaster (final WebSocket.In<JsonNode> in, final WebSocket.Out<JsonNode> out )
 {        
         in.onMessage(new Callback<JsonNode>() {
     public void invoke(JsonNode event) throws JsonParseException, JsonMappingException, IOException {                 

    ObjectMapper mapper = new ObjectMapper();               

    @SuppressWarnings("unchecked")
        Map<String,ArrayList<Object>> jsonMap = mapper.readValue(event, Map.class); 
    GesturePoints gp = new GesturePoints();

    gp.setPoints(jsonMap);
    localActor.tell(gp);            
     }
  });     } 

this is the local Actor system in play framework

package controllers;

import Com.RubineEngine.GesturePoints.*;

import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

public class LocalActor extends UntypedActor {

     /**
     * 
     */

    ActorRef masterActor; // = getContext().actorFor("akka://MasterNode@127.0.0.1:2552/user/masterActor");
     LoggingAdapter log = Logging.getLogger(getContext().system(), this);

    @Override
    public void onReceive(Object arg) throws Exception {
        System.out.println(" Local Actor 1");
          if(arg instanceof GesturePoints)
         {  System.out.println(" local Actor 2");
              masterActor.tell(arg , getSelf());    
              System.out.println(" Local Actor 3");}    
         else 
         {unhandled(arg);}
    }


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

}

this is the remote akka system master Node that creates the master actor

package Rubine_Cluster;

import java.util.Arrays;

import com.typesafe.config.ConfigFactory;

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

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

      public MasterNode() {

        //Create a child actor of this actor upon initialization 
        system = ActorSystem.create("MasterNode", ConfigFactory.load()
            .getConfig("masterNode"));
         masterActor = system.actorOf(new Props(MasterActor.class),"masterActor");  

      }


      public void startup() {

      }

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

this is the remote actor system created by the MasterNode

public class MasterActor extends UntypedActor {

    /**
     * 
     */

    ActorSystem system = ActorSystem.create("container");

    ActorRef worker1;

    //public MasterActor(){}

    @Override
    public void onReceive(Object message) throws Exception {
        System.out.println(" Master Actor 5");

         if(message instanceof GesturePoints)
         {  //GesturePoints gp = (GesturePoints) message;
              System.out.println(" Master Actor 1");             
         try {      worker1.tell(message, getSelf());

             System.out.println(" Master Actor 2");
                } catch (Exception e) {
                  getSender().tell(new akka.actor.Status.Failure(e), getSelf());
                  throw e;
                }

    }
         else{ unhandled(message);}
  }  

    public void preStart()
    {
      worker1 = getContext().actorFor("akka://WorkerNode@127.0.0.1:2553/user/workerActor");
    }

}

I think I got the referencing wrong or probably were to send the message any suggestion is welcome

faisal abdulai
  • 3,739
  • 8
  • 44
  • 66
  • It's not a "bug" in Eclipse, that much I know. – Hovercraft Full Of Eels Oct 07 '12 at 15:40
  • but do you have any idea what the problem might be – faisal abdulai Oct 07 '12 at 15:44
  • 1
    One possibility: the standard out has been redirected somehow. I'm not familiar with Akka and so cannot comment on it. As an aside, what you're trying to do would be better done using logging, I think. – Hovercraft Full Of Eels Oct 07 '12 at 15:45
  • If you run your program on the commandline, do you see the output? (This would check if this is a Eclipse related problem) – Uwe L. Korn Oct 07 '12 at 16:55
  • Umm, you should most definitely not create another ActorSystem within your UntypedActor. – Viktor Klang Oct 07 '12 at 17:37
  • 2
    To be honest, there isn't much stuff in the right place here. First of all, you aren't sending the master actor any messages, so onReceive won't be called at all. Also, the code for creating the worker doesn't exist. Are you saying that this piece of code works even outside of Eclipse? – Viktor Klang Oct 07 '12 at 18:42
  • Faisal: you should probably take all that @Viktor states to heart. Something tells me that he knows a thing or two (more like just about *everything*) about Akka. – Hovercraft Full Of Eels Oct 07 '12 at 19:37
  • yeah , I alo beleive so but looked like I posted the wrong question and had to edit – faisal abdulai Oct 07 '12 at 19:42
  • @Viktor Klang I have added some more code snippets and edited the title . It should now make clearer the question.@Viktor – faisal abdulai Oct 07 '12 at 19:46
  • Remove "ActorSystem system = ActorSystem.create("container");" and you're still not sending any messages to the masterActor, so there is no message for him to "onReceive". – Viktor Klang Oct 07 '12 at 22:57
  • But is the remote lookup referencing done the right way I followed what is given in the tutorials – faisal abdulai Oct 07 '12 at 23:44
  • after going through the system again I found that the two remote systems use two different ports but when I run them in eclipse the two systems use the same port number which is 2552. Even though one is configured for 2552 and the other is 2553. I checked the application.conf file the have different configurations of port number for each system. – faisal abdulai Oct 08 '12 at 02:59

0 Answers0