changeset 90:9cdc24bae625

ring test
author one
date Sat, 13 Feb 2010 04:16:15 +0900
parents b658ff1eb90f
children 4df1d50df52a
files src/fdl/AcceptHandler.java src/fdl/PSXLindaImpl.java src/fdl/test/debug/ConfigurationManager.java src/fdl/test/debug/ConfigurationManagerEngine.java src/fdl/test/debug/MetaProtocolEngine.java
diffstat 5 files changed, 59 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/src/fdl/AcceptHandler.java	Thu Feb 11 16:26:04 2010 +0900
+++ b/src/fdl/AcceptHandler.java	Sat Feb 13 04:16:15 2010 +0900
@@ -31,6 +31,7 @@
         // アクセプト処理
         SocketChannel channel = serverChannel.accept();
         channel.configureBlocking(false);
+        //channel.socket().setTcpNoDelay(true);
         fds.log(Level.INFO,"Server: accepted "+channel.socket());
 
         // TCP N Delay を ServerSocketChannel のオプションに指定する
--- a/src/fdl/PSXLindaImpl.java	Thu Feb 11 16:26:04 2010 +0900
+++ b/src/fdl/PSXLindaImpl.java	Sat Feb 13 04:16:15 2010 +0900
@@ -65,12 +65,6 @@
 			if (debug) {
 			    fdl.log(Level.INFO,"waiting for connect");
 			}
-			if (false) {
-				try {
-					wait(2000);
-				} catch (InterruptedException e) {
-				}
-			}
 		}
 		fdl.log(Level.INFO,"Linda client connect to "+socketChannel);
         socketChannel.register(selector,SelectionKey.OP_READ,this);
@@ -117,6 +111,15 @@
 		}
 	}
 
+	public void close() {
+		if (socketChannel != null) {
+			try {
+				socketChannel.close();
+			} catch (IOException e) {
+			}
+		}
+	}
+
 	private void checkConnect(String s) {
 		fdl.log(Level.INFO, "Connected:"+ s +": "
 		    +socketChannel.isConnected());
@@ -180,7 +183,6 @@
 
 	public void send(ByteBuffer command, ByteBuffer data) {
 		PSX.send(socketChannel, command, data);
-		fdl.log(Level.INFO,"Linda client sent data to "+socketChannel + " " + new String(data.array()));
 	}
 
 
--- a/src/fdl/test/debug/ConfigurationManager.java	Thu Feb 11 16:26:04 2010 +0900
+++ b/src/fdl/test/debug/ConfigurationManager.java	Sat Feb 13 04:16:15 2010 +0900
@@ -15,20 +15,26 @@
 
 public class ConfigurationManager {
 	private static int nodeNum = 2;
+	private static int relayNum = 1;
+	private static int relaySize = 1024;
 	private static String usageString
-		= "ConfigurationManager -nodes NODENUM";
+		= "ConfigurationManager -nodes NODENUM -relay RELAYNUM -size RELAYSIZE";
 	
 	public static void main(String[] args) {
 		for (int i = 0; i < args.length; i++) {
 			if ("-nodes".equals(args[i])) {
 				nodeNum = Integer.parseInt(args[++i]);
+			} else if ("-relay".equals(args[i])) {
+				relayNum = Integer.parseInt(args[++i]);
+			} else if ("-size".equals(args[i])) {
+				relaySize = Integer.parseInt(args[++i]);
 			} else {
 				System.err.println(usageString);
 			}
 		}
 		try {
 			FDLindaNode manager = new FDLindaNode(FDLindaNode.DEFAULTPORT);
-			MetaEngine me = new ConfigurationManagerEngine(manager.getMetaLinda(), nodeNum);
+			MetaEngine me = new ConfigurationManagerEngine(manager.getMetaLinda(), nodeNum, relayNum, relaySize);
 			manager.setMetaEngine(me);
 			manager.mainLoop();
 		} catch (IOException e) {
--- a/src/fdl/test/debug/ConfigurationManagerEngine.java	Thu Feb 11 16:26:04 2010 +0900
+++ b/src/fdl/test/debug/ConfigurationManagerEngine.java	Sat Feb 13 04:16:15 2010 +0900
@@ -26,6 +26,8 @@
 	public static final int DEBUGSTART = DEBUG + 1000;
 	
 	private int nodeNum = 0;
+	private int relayNum = 0;
+	private int relaySize = 1;
 	private MetaLinda ml;
 	private NodeInfo[] nodes;
 	private boolean running = true;
@@ -73,10 +75,10 @@
 				ml.in(MANAGE, this);
 			} else {
 				print("All link configured!");
-				// 実験開始を通知
-				nodes[0].linda.out(START, ByteBuffer.wrap("test".getBytes()));
+				// TREE実験開始を通知
+				// nodes[0].linda.out(START, ByteBuffer.wrap("test".getBytes()));
 				// DebugRing 開始を通知
-				nodes[0].linda.out(DEBUGSTART, ByteBuffer.wrap("relay,10,1024".getBytes()));
+				nodes[0].linda.out(DEBUGSTART, ByteBuffer.wrap(("relay,"+new Integer(relayNum).toString()+","+new Integer(relaySize)).getBytes()));
 				ml.in(MANAGE, new ConfirmFinish());
 			}
 		}
@@ -85,6 +87,7 @@
 	
 	private class ConfirmFinish implements PSXCallback {
 		public void callback(ByteBuffer reply) {
+			System.out.println(new Integer(nodeNum).toString() + "," + new String(reply.array()));
 			nodes[0].linda.out(DEBUGSTART, ByteBuffer.wrap("shutdown".getBytes()));
 			print("Finish token");
 			try {
@@ -97,10 +100,12 @@
 
 	}
 	
-	public ConfigurationManagerEngine(MetaLinda metaLinda, int nodeNum) {
+	public ConfigurationManagerEngine(MetaLinda metaLinda, int nodeNum, int relayNum, int relaySize) {
 		// initialize
 		this.ml = metaLinda;
 		this.nodeNum = nodeNum;
+		this.relayNum = relayNum;
+		this.relaySize = relaySize;
 		nodes = new NodeInfo[nodeNum];
 	}
 
--- a/src/fdl/test/debug/MetaProtocolEngine.java	Thu Feb 11 16:26:04 2010 +0900
+++ b/src/fdl/test/debug/MetaProtocolEngine.java	Sat Feb 13 04:16:15 2010 +0900
@@ -60,6 +60,8 @@
 	
 	private int relayNum, relaySize, relayCounter;
 	
+	private Date startTime, endTime;
+	
 	// Callback class
 	class AcceptXMLCallback implements PSXCallback {
 		int tid;
@@ -167,36 +169,37 @@
 				ml.in(BODY);
 				ml.out(BODY, reply);
 				print("Update body");
+			} else if (str.equals("shutdown") && (tid == RINGLEFT || tid == RINGRIGHT)) {
+				print("get shutdown command");
+				if (nodeId != 0) {
+					Routing r = null;
+					if (tid == RINGLEFT) { 
+						r = nodes.get(new Integer(RINGRIGHT));
+					} else if (tid == RINGRIGHT) { 
+						r = nodes.get(new Integer(RINGLEFT));
+					}
+					print("out");
+					PSXReply o = r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
+					while (ml.fdl.qsize != 0)
+						ml.sync(1);
+					print("sync");
+					((PSXLindaImpl) r.linda).close();
+				}
+				running = false;
+				return;
 			} else if (nodeId == 0 && tid == RINGLEFT) {
 				relayCounter++;
 				print(new Integer(relayCounter).toString() + " relay");
 				if (relayCounter >= relayNum) {
-					sendLocalHostName();
+					// 実験終了
+					endTime = new Date();
+					Double resultTime = new Double(((endTime.getTime() - startTime.getTime()) / (double)relayNum)); 
+					ByteBuffer data = ByteBuffer.wrap(resultTime.toString().getBytes());
+					manager.out(MANAGE, data);
+					//sendLocalHostName();
 					ml.in(tid, this);
 					return;
 				}
-			} else if (str.equals("shutdown")) {
-				if (tid == RINGLEFT) { 
-					Routing r = nodes.get(new Integer(RINGRIGHT));
-					r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
-					try {
-						r.linda.sync(1);
-					} catch (IOException e) {
-						e.printStackTrace();
-					}
-					running = false;
-					return;
-				} else if (tid == RINGRIGHT) { 
-					Routing r = nodes.get(new Integer(RINGLEFT));
-					r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
-					try {
-						r.linda.sync(1);
-					} catch (IOException e) {
-						e.printStackTrace();
-					}
-					running = false;
-					return;
-				}
 			}
 				
 			Iterator<Integer> it = routing.route.iterator();
@@ -241,12 +244,15 @@
 				print("relay num=" + new Integer(relayNum).toString() + " size=" + new Integer(relaySize).toString());
 				
 				Routing r = nodes.get(new Integer(RINGRIGHT));
+
+				// 実験開始
+				startTime = new Date();
 				r.linda.out(r.dstId, ByteBuffer.wrap(new byte[relaySize]));
 				ml.in(DEBUGSTART, this);
 			} else if (command.equals("shutdown")) {
 				Routing r = nodes.get(new Integer(RINGRIGHT));
 				r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
-				running = false;
+				//running = false;
 			}
 		}
 	}
@@ -272,6 +278,8 @@
 		while (running) {
 			ml.sync();
 		}
+		print("Terminated");
+
 	}
 	
 	protected void initPoller() {