2012-10-08 60 views
0

我正在使用java的play framework 2系統。play框架使用集成了play framework的akka​​系統與遠程akka系統連接。遠程akka系統由主節點和工作節點組成。這兩個系統與eclipse juno IDE在同一臺計算機上 我爲主節點配置了兩個端口2552,爲工作節點配置了端口2553. play 2框架中的akka​​節點由系統自己選擇。預計播放框架中的akka​​系統將通過使用akka配置進行遠程查找來通過遠程主節點的信息。主節點實習生也通過遠程查詢將消息傳遞給遠程工作人員進行處理。主節點和工作節點有thier application.conf文件在以下formart:遠程akka系統端口衝突

src/main/resources/application.conf 

但是在啓動時的主節點和工作節點都決定使用的端口號2552爲他們的通信。我提供下面的代碼片段:

這是我爲播放framewrok application.config文件的代碼。

localNode { 
    akka { 
     actor { 
      provider = "akka.remote.RemoteActorRefProvider" 
     } 
     remote { 
      transport = "akka.remote.netty.NettyRemoteTransport" 
      netty { 
       hostname = "127.0.0.1" 
       port = 0 
      } 
     } 
    } 
} 

這是該劇的configuation LOCALNODE

package controllers; 

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

import org.codehaus.jackson.JsonNode; 
import org.codehaus.jackson.JsonParseException; 
import org.codehaus.jackson.map.JsonMappingException; 
import org.codehaus.jackson.map.ObjectMapper; 

import play.libs.F.Callback; 
import play.mvc.WebSocket; 
import akka.actor.ActorRef; 
import akka.actor.ActorSystem; 
import akka.actor.Props; 
import akka.serialization.Serialization; 
import akka.serialization.SerializationExtension; 

import com.typesafe.config.ConfigFactory; 
import Com.RubineEngine.GesturePoints.*; 

public class LocalNode { 

    ActorSystem csystem; 
    ActorRef localActor ; 


    public LocalNode() { 

     //We create the actor container and a child upon initialization 
    csystem = ActorSystem.create("LocalNode", ConfigFactory.load().getConfig("localNode")); 
    localActor = csystem.actorOf(new Props(LocalActor.class),"localActor"); 
    } 


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

    } 

    public void connectMaster() 
    { 

    } 


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

這是在劇中框架阿卡演員代碼

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://[email protected]: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(" Welcome home " , getSelf()); 
       System.out.println(" Local Actor 3");}  
     else 
     {unhandled(arg);} 
    } 


    public void preStart() 
    { 
     masterActor = getContext().actorFor("akka://[email protected]:2553/user/masterActor"); 
    } 
} 

這是主節點應用程序的代碼.conf

masterNode { 

akka { 
    actor { 
    provider = "akka.remote.RemoteActorRefProvider" 
    } 
    remote { 
    transport = "akka.remote.netty.NettyRemoteTransport" 
    netty { 
     hostname = "127.0.0.1" 
     remote.netty.port = 2553 
    } 
} 
} 
} 

這是主節點

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

的代碼,這是針對主阿卡演員代碼

package Rubine_Cluster; 

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

import Com.RubineEngine.GesturePoints.*; 
import akka.actor.*; 
import akka.serialization.Serialization; 
import akka.serialization.SerializationExtension; 
import akka.serialization.Serializer; 





public class MasterActor extends UntypedActor { 

    /** 
    * 
    */ 

    ActorRef worker1; 



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

     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://[email protected]:2552/user/workerActor"); 
    } 

} 

這對於工作節點application.conf

workerNode { 

akka { 
    actor { 
    provider = "akka.remote.RemoteActorRefProvider" 
    } 
    remote { 
    transport = "akka.remote.netty.NettyRemoteTransport" 
    netty { 
     hostname = "127.0.0.1" 
     remote.netty.port = 2552 
    } 
} 
} 
} 

代碼這是工作人員的代碼

package com.theta.gesture; 

import com.typesafe.config.ConfigFactory; 
import akka.actor.ActorRef; 
import akka.actor.ActorSystem; 
import akka.actor.Props; 
import akka.kernel.Bootable; 


public class WorkerNode implements Bootable{ 
    ActorSystem system; 
    ActorRef worker; 

    WorkerNode(){ 
     system = ActorSystem.create("WorkerNode", ConfigFactory.load() 
       .getConfig("workerNode")); 
      ActorRef workerActor = system.actorOf(new Props(WorkerActor.class),"workerActor");    
} 


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

    } 

    public void startup() { 
    }  
} 

這是在工人項目男主角代碼

package com.theta.gesture; 

import java.util.ArrayList; 
import java.util.Map; 

import Com.RubineEngine.GesturePoints.GesturePoints; 
import akka.actor.*; 

public class WorkerActor extends UntypedActor { 

    private static double    DIST_SQ_THRESHOLD = 3 * 3; /* threshold to eliminate mouse jitter */ 

    @Override 
    public void onReceive(Object msg) throws Exception { 

     if(msg instanceof GesturePoints) 
     { GesturePoints message = (GesturePoints) msg; 
      initial_Theta(message);} 

     else {unhandled(msg);} 
    } 

    public void initial_Theta(GesturePoints p) 
    {  System.out.println(" Worker Actor 1");   
     if(p.getPoints().get("X").size() < 3) //The number of x coordinates as size 
     { return;}      

     System.out.println(" Worker Actor 2"); 
      double magsq,dx,dy, recip; 

      dx = (double) ((Integer)p.getPoints().get("x").get(2) - (Integer)p.getPoints().get("x").get(0)) ; 
      dy = ((Double)p.getPoints().get("y").get(2)) - ((Double)p.getPoints().get("y").get(0)); 

      magsq = dx * dx + dy * dy; 
      if(magsq > DIST_SQ_THRESHOLD) 
      { 
       recip = 1/Math.sqrt(magsq); 
       double initial_cos = dx * recip; 

       System.out.println(" Worker Actor 3"); 
       double initial_sin = dy * recip; 

       System.out.println("Feature cos " + initial_cos); 
       System.out.println("Gesture sin " + initial_sin); 
      } 
     } } 

這是對工作節點

[INFO] [10/08/2012 12:12:44.486] [main] [ActorSystem(WorkerNode)] REMOTE: 
[email protected]://[email protected]:2552 

此控制檯信息主節點控制檯信息

[INFO] [10/08/2012 12:13:34.633] [main] [ActorSystem(MasterNode)] REMOTE: 
[email protected]://[email protected]:2552 

關於這種情況的可能過程和建議的解決方案的任何想法是深受追捧

回答

3

嵌套部分內的「remote.netty.port = X」應爲「port = X」