changeset 57:48bb577a313f

Protocol Engine for cluster
author axmo
date Thu, 12 Feb 2009 14:42:27 +0900
parents 0143623aa465
children c33abea8cddc
files src/fdl/test/transfer/cluster/FDLServWithSend.java src/fdl/test/transfer/cluster/MetaProtocolEngine.java src/fdl/test/transfer/cluster/ProtocolEngine.java src/fdl/test/transfer/cluster/TestSend.java
diffstat 4 files changed, 148 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/transfer/cluster/FDLServWithSend.java	Thu Feb 12 14:42:27 2009 +0900
@@ -0,0 +1,40 @@
+package fdl.test.transfer.cluster;
+
+import java.io.IOException;
+
+import fdl.FDLindaServ;
+import fdl.MetaLinda;
+
+
+public class FDLServWithSend extends FDLindaServ {
+	public FDLServWithSend(int port) throws IOException {
+		super(port);
+	}
+
+	private static String host = "localhost";
+	
+	@Override public void mainLoop() {
+		System.out.println("change mainloop");
+		MetaLinda ml = new MetaLinda(tupleSpace, this);
+		mpe = new MetaProtocolEngine(ml, host);
+		mpe.mainLoop();
+	}
+	
+	public static void main(String[] args){
+		for (int i=0; i<args.length; ++i) {
+			if("-send".equals(args[i])){
+				host = args[++i];
+			} else {
+	        System.err.println("引数指定の誤り:未知の引数が指定されました");
+            }
+		}
+		try {
+			FDLServWithSend serv;
+			serv = new FDLServWithSend(10000);
+			serv.mainLoop();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fdl/test/transfer/cluster/MetaProtocolEngine.java	Thu Feb 12 14:42:27 2009 +0900
@@ -0,0 +1,99 @@
+package fdl.test.transfer.cluster;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+
+import fdl.MetaEngine;
+
+import fdl.MetaLinda;
+import fdl.PSXLinda;
+import fdl.PSXReply;
+
+public class MetaProtocolEngine implements MetaEngine {
+	private int id = 10;
+	
+	private PSXLinda psx;
+	MetaLinda fdl1;
+	String host;
+	int port1 = 10000;
+	private PSXLinda psx1;
+	private ByteBuffer data2 = ByteBuffer.allocate(10);
+	
+	public MetaProtocolEngine(MetaLinda ml, String host) {
+		this.host = host;
+		this.fdl1 = ml;
+	}
+
+	public void mainLoop(){
+		boolean connect = true;
+		System.out.println("MetaEngine Start");
+		while(connect){
+		try {
+			initConnect();
+			sendData();
+			transfer();
+			connect = false;
+		} catch (IOException e) {
+			try {
+				Thread.sleep(40);
+			} catch (InterruptedException e1) {
+			}
+		}
+		}
+	}
+
+	private void initConnect(){
+		boolean connectpsx = true;
+		while(connectpsx){
+		try {
+			psx = fdl1.open(host,port1);
+			connectpsx = false;
+		} catch (IOException e) {
+			try {
+				Thread.sleep(40);
+			} catch (InterruptedException e1) {
+				e1.printStackTrace();
+			}
+		}
+		}
+		System.out.println("Connect "+port1);
+		psx1 = fdl1;
+	}
+	
+	private void sendData() throws IOException{
+		boolean connectSend = true;
+		ByteBuffer send = ByteBuffer.allocate(1024);
+		send.putInt(12);
+		send.flip();
+		while(connectSend){
+		psx.out(id, send);
+		psx.sync(1);
+		System.out.println("Send Data 10001");
+		connectSend = false;
+		}
+	}
+
+	private void transfer() throws IOException {
+		boolean running = true;
+		PSXReply in = psx.in(id);
+		System.out.println("PSXReply "+port1);
+		while (running) {
+			if(in.ready()){
+				data2 = in.getData();
+				int i = data2.getInt();
+				data2.rewind();
+				//outしたbytebufferの変更をこれ以降やっちゃいけない
+				psx1.out(id,data2);
+				
+				System.out.println("IntData0 "+port1 +i);
+				fdl1.sync();
+					running = false;
+					break;
+			}
+		}
+	}
+
+	
+}
+
--- a/src/fdl/test/transfer/cluster/ProtocolEngine.java	Wed Feb 11 20:43:55 2009 +0900
+++ b/src/fdl/test/transfer/cluster/ProtocolEngine.java	Thu Feb 12 14:42:27 2009 +0900
@@ -37,7 +37,7 @@
 			send.putInt(12);
 			send.flip();
 			getpsx.out(id , send);
-			getpsx.sync();
+			fdl.sync(1);
 			System.out.println("Send Data");
 			// psxにデータを用意
 			boolean running = true;
@@ -50,7 +50,7 @@
 					sendpsx.out(id,data2);
 					//runningフラグをfalseする
 					running = false;
-					sendpsx.sync();
+					sendpsx.sync(1);
 					System.out.println("Transfer Data");
 					break;
 				}
--- a/src/fdl/test/transfer/cluster/TestSend.java	Wed Feb 11 20:43:55 2009 +0900
+++ b/src/fdl/test/transfer/cluster/TestSend.java	Thu Feb 12 14:42:27 2009 +0900
@@ -6,19 +6,15 @@
 import fdl.FederatedLinda;
 import fdl.PSXLinda;
 
-public class TestSend extends Thread {
-	PSXLinda psxsend;
-	FederatedLinda fdlsend;
-	private int port;
-	
-	public TestSend(int port1) {
-		this.port = port1;
-	}
+public class TestSend {
+	static PSXLinda psxsend;
+	static FederatedLinda fdlsend;
+	private static int port = 10000;
 
-	public void run(){
+	public static void main(String[] args){
 		int id = 10;
 		int i;
-		String host = "127.0.0.1";
+		String host = "cls001.cs.ie.u-ryukyu.ac.jp";
 		ByteBuffer send = ByteBuffer.allocate(1024);
 		send.putInt(12);
 		send.flip();
@@ -34,7 +30,7 @@
 			System.out.println("Connect Host1");
 			psxsend.out(id, send);
 			System.out.println("regist Que");
-			fdlsend.sync(1);
+			fdlsend.sync();
 			System.out.println("Send Data");
 			connect = false;
 		}catch (IOException e) {