changeset 97:0ea086f0e96f fuchita

main loop modification, for easy meta engine addition. add comments.
author one
date Wed, 26 May 2010 10:49:50 +0900
parents 96c63bc659d4
children efe50b1204f3
files src/fdl/FDLindaServ.java src/fdl/MetaEngine.java src/fdl/MetaLogEngine.java src/fdl/NullMetaEngine.java src/fdl/PSXLinda.java src/fdl/test/TestPSXLinda.java src/fdl/test/TestWaitRd.java src/fdl/test/debug/ConfigurationManagerEngine.java src/fdl/test/debug/FDLindaNode.java src/fdl/test/debug/MetaProtocolEngine.java src/fdl/test/debug2/ConfigurationManagerEngine.java src/fdl/test/debug2/FDLindaNode.java src/fdl/test/debug2/MetaProtocolEngine.java src/fdl/test/metaTransfer/FDLServWithSend.java src/fdl/test/metaTransfer/MetaProtocolEngine.java src/fdl/test/metaTransfer/MetaProtocolEngine_not.java src/fdl/test/metaTransfer/Ring/FDLServWithSend.java src/fdl/test/metaTransfer/Ring/MetaProtocolEngine.java src/fdl/test/topology/FDLindaNode.java src/fdl/test/topology/MetaProtocolEngine.java src/fdl/test/topology/TopologyManagerEngine.java src/fdl/test/transfer/cluster/FDLServWithSendMeta.java src/fdl/test/transfer/cluster/MetaProtocolEngine.java src/fdl/test/transfer/two/ProtocolEngine.java src/fdl/test2/TestRing.java
diffstat 25 files changed, 169 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/src/fdl/FDLindaServ.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/FDLindaServ.java	Wed May 26 10:49:50 2010 +0900
@@ -12,7 +12,6 @@
 import java.util.Iterator;
 import java.util.logging.Level;
 
-
 public class FDLindaServ  {
 	static final int MAX_REQ = 1;
 	static final int FAIL = (-1);
@@ -24,7 +23,7 @@
 	public TupleSpace tupleSpace;
 	public MetaEngine me;
 	
-	public static void main(final String[] args) {
+	public static void main(MetaEngine me, final String[] args) {
 		final String usages = "usage: FDLindaServ [-d] [-p port]";
 		
 		int port = DEF_PORT;
@@ -44,17 +43,21 @@
 		try {
 			FDLindaServ serv;
 			serv = new FDLindaServ(port);
-			serv.mainLoop();
+			serv.mainLoop(me,new MetaLinda(serv.tupleSpace, serv));
 		} catch (IOException e) {
 			System.err.println("Server Communiation Problem.");
 		}
 	}
-	
+
 	public void mainLoop() {
 		MetaLinda ml = new MetaLinda(tupleSpace, this);
-		me = new NullMetaEngine(ml);
+		me = new NullMetaEngine();
 		//me = new MetaLogEngine(ml);
-		me.mainLoop();
+		me.mainLoop(ml);
+	}
+	
+	public void mainLoop(MetaEngine me, MetaLinda ml) {
+		me.mainLoop(ml);
 	}
 
 	public FDLindaServ(int port) throws IOException {
@@ -132,4 +135,8 @@
 		if (level==Level.SEVERE)
 			new IOException().setStackTrace(null);
 	}
+
+	public static void main(final String[] args) {
+		main(new NullMetaEngine(),args);
+	}
 }
--- a/src/fdl/MetaEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/MetaEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -1,5 +1,6 @@
 package fdl;
 
 public interface MetaEngine {
-	void mainLoop();
+	void mainLoop(MetaLinda ml);
+
 }
\ No newline at end of file
--- a/src/fdl/MetaLogEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/MetaLogEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -28,7 +28,7 @@
 			do {
 				data = commDebug.getLog();
 				if (data!=null) break;
-				meta.sync();
+				meta.sync(0);
 			} while (running);
 			if (running) {
 				meta.out(PSX.META_MONITOR_DATA, data);
@@ -36,11 +36,11 @@
 			}
 		}};
 	
-	public void mainLoop() {
+	public void mainLoop(MetaLinda meta) {
 		meta.in(PSX.META_MONITOR,monitor_callback_start);
 		meta.in(PSX.META_STOP, new PSXCallback() {public void callback(ByteBuffer reply) {
 			running = false;}});
 		while(running) 
-			meta.sync();
+			meta.sync(0);
 	}
 }
--- a/src/fdl/NullMetaEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/NullMetaEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -3,17 +3,17 @@
 import java.nio.ByteBuffer;
 
 public class NullMetaEngine implements MetaEngine {
-	public MetaLinda meta;
 	public boolean running=true;
 
-	public NullMetaEngine(MetaLinda meta) {
-		this.meta = meta;
+	public NullMetaEngine() {
 	}
 	
-	public void mainLoop() {
+	public void mainLoop(MetaLinda meta) {
 		meta.in(PSX.META_STOP, new PSXCallback() {public void callback(ByteBuffer reply) {
 			running = false;}});
 		while(running) 
-			meta.sync();
+			meta.sync(0);
 	}
+
+
 }
--- a/src/fdl/PSXLinda.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/PSXLinda.java	Wed May 26 10:49:50 2010 +0900
@@ -3,36 +3,137 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 
+/**
+ * @author kono
+ *
+ */
+/**
+ * @author kono
+ *
+ */
+/**
+ * @author kono
+ *
+ */
 public interface PSXLinda {
 
-
+	
+	/**
+	 * send IN request to the linda
+	 * Tuple with id will be removed, and the value is returned in the reply
+	 * @param id
+	 * @return wait for this request
+	 */
 	public PSXReply in(int id) ;
 
+	/**
+	 * send IN request and set call back for reply
+	 * @param id
+	 * @param callback
+	 */
 	public void in(int id, PSXCallback callback);
 
+	/**
+	 * send Check request to the linda
+	 * Tuple with id will not be removed, it return even if there is no tuple for
+	 * this id
+	 * @param id
+	 * @return wait for this request
+	 */
 	public PSXReply ck(int id) ;
 
+	/**
+	 * send Check request and set call back for reply
+	 * @param id
+	 * @param callback
+	 */
 	public void ck(int id, PSXCallback callback) ;
 
+	/**
+	 * send a Tuple to the linda
+	 * Tuple may stack in the linda, mutiple out is possible.
+	 * No blocking.
+	 * this id
+	 * @param id
+	 * @return wait for this request
+	 */
 	public PSXReply out(int id, ByteBuffer data) ;
 
+	/**
+	 * replace a Tuple in the linda
+	 * the old value is returned in the reply
+	 * @param id
+	 * @return wait for this request
+	 */
 	public PSXReply update(int id, ByteBuffer data) ;
 
+	/**
+	 * send Update request and set call back for reply
+	 * @param id
+	 * @param callback
+	 */
 	public void update(int id, ByteBuffer data,PSXCallback callback) ;
 
+	/**
+	 * Read the tuple in the linda, do not remove the tuple.
+	 * it return it's value
+	 * @param id
+	 * @return wait for this request
+	 */
 	public PSXReply rd(int id) ;
 
+	/**
+	 * send Read request and set call back for reply
+	 * @param id
+	 * @param callback
+	 */
 	public void rd(int id, PSXCallback callback) ;
 
-	public PSXLinda add(PSXLinda linda) ;
+
+	/**
+	 * Wait for newly incoming tuple for this id. 
+	 * Existing tuple is ingored.
+	 * Read the tuple in the linda, do not remove the tuple.
+	 * it return it's value
+	 * @param id
+	 * @return wait for this request
+	 */
+	public PSXReply waitRd(int i);
 
+	/**
+	 * send Read request and set call back for reply
+	 * @param id
+	 * @param callback
+	 */
+	public void waitRd(int i, PSXCallback callback);
+	
+	/**
+	 * Send all registered reqests, and read incoming replies.
+	 * No wait
+	 * @return
+	 * @throws IOException
+	 */
 	public int sync() throws IOException ;
 
+	/**
+	 * Send all registered reqests, and read incoming replies.
+	 * @param mtime     wait for mtime msec, if 0 this waits indefinitely.
+	 * @return
+	 * @throws IOException
+	 */
 	public int sync(long mtime) throws IOException ;
 
+	/**
+	 * Internal use
+	 * @param linda
+	 * @return
+	 */
+	public PSXLinda add(PSXLinda linda) ;
+	
+	/*
+	 * Intenal use
+	 * sned data for this port
+	 */
 	public void send(ByteBuffer command, ByteBuffer data);
 
-	public void waitRd(int i, PSXCallback callback);
-	
-	public PSXReply waitRd(int i);
 }
--- a/src/fdl/test/TestPSXLinda.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/TestPSXLinda.java	Wed May 26 10:49:50 2010 +0900
@@ -69,7 +69,7 @@
 			int cnt=0;
 			while(!r.ready()) {
 				// psx.sync(1000);
-				psx.sync();
+				psx.sync(0);
 				System.out.println("Waiting...."+(cnt++));
 			}
 
@@ -77,7 +77,7 @@
 			
 			data.clear();
 			psx.out(PSX.META_STOP, data);
-			psx.sync();
+			psx.sync(0);
 			
 		} catch (IOException e) {
 			System.err.println("Communication failure.");
--- a/src/fdl/test/TestWaitRd.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/TestWaitRd.java	Wed May 26 10:49:50 2010 +0900
@@ -9,7 +9,6 @@
 import fdl.FDLindaServ;
 import fdl.FederatedLinda;
 import fdl.PSX;
-import fdl.PSXCallback;
 import fdl.PSXLinda;
 import fdl.PSXReply;
 
@@ -44,18 +43,18 @@
 				sleep(1000);
 				sendData(psx,1,0);
 				psx.sync(1000);
-				waitIn(psx,1);
+				in_wait(psx,1);
 				sendData(psx,1,1);
 				psx.sync(1000);
-				waitIn(psx,1);
+				in_wait(psx,1);
 				sendData(psx,1,2);
 				psx.sync(1000);
-				waitIn(psx,1);
+				in_wait(psx,1);
 
 				for(int i=3;i<10;i++) {
 					sendData(psx,1,i);
 					psx.sync(1000);
-					waitIn(psx,1);
+					in_wait(psx,1);
 				}
 				sleep(1000);
 			} catch (IOException e) {
@@ -134,7 +133,7 @@
 		int cnt=0;
 		while(!r.ready()) {
 			// psx.sync(1000);
-			psx.sync();
+			psx.sync(10);
 			System.out.println(name+": Waiting...."+(cnt++));
 		}
 		print_id(r);
@@ -149,7 +148,7 @@
 		return data;
 	}
 
-	public void waitIn(PSXLinda psx, int i) throws IOException {
+	public void in_wait(PSXLinda psx, int i) throws IOException {
 		PSXReply r = psx.in(i);
 		while(! r.ready()) { 
 			psx.sync(10); 
--- a/src/fdl/test/debug/ConfigurationManagerEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/debug/ConfigurationManagerEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -109,11 +109,11 @@
 		nodes = new NodeInfo[nodeNum];
 	}
 
-	public void mainLoop() {
+	public void mainLoop(MetaLinda ml1) {
 		// regist poll tuple id
 		ml.in(MANAGE, new AcceptNewNode());
 		while (running)
-			ml.sync();
+			ml.sync(0);
 	}
 	
 	private void linkNodes() {
--- a/src/fdl/test/debug/FDLindaNode.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/debug/FDLindaNode.java	Wed May 26 10:49:50 2010 +0900
@@ -31,7 +31,7 @@
 	}
 	
 	@Override public void mainLoop() {
-		me.mainLoop();
+		me.mainLoop(ml);
 	}
 	public void setMetaEngine(MetaEngine me) {
 		this.me = me; 
--- a/src/fdl/test/debug/MetaProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/debug/MetaProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -266,10 +266,10 @@
 		sendLocalHostName();
 	}
 
-	public void mainLoop() {
+	public void mainLoop(MetaLinda ml) {
 		initPoller();
 		while (running) {
-			ml.sync();
+			ml.sync(0);
 		}
 		print("Terminated" + nodeId
 				+ " replies=" + ml.replies.size()
--- a/src/fdl/test/debug2/ConfigurationManagerEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/debug2/ConfigurationManagerEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -8,9 +8,9 @@
 public class ConfigurationManagerEngine implements MetaEngine {
 	public static final int DEFAULTPORT = 10000;
 	
-	private int nodeNum = 0;
-	private int relayNum = 0;
-	private int relaySize = 1;
+	public int nodeNum = 0;
+	public int relayNum = 0;
+	public int relaySize = 1;
 	private MetaLinda ml;
 	private NodeInfo[] nodes;
 	private boolean running = true;
@@ -103,12 +103,12 @@
 		nodes = new NodeInfo[nodeNum];
 	}
 
-	public void mainLoop() {
+	public void mainLoop(MetaLinda ml1) {
 		// resist poll tuple id
 		ml.in(TupleId.MANAGE.id, new AcceptNewNode());
 		ml.in(TupleId.DEBUG.id, new RingLoop());
 		while (running)
-			ml.sync();
+			ml.sync(0);
 	}
 	
 	private void linkNodes() {
--- a/src/fdl/test/debug2/FDLindaNode.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/debug2/FDLindaNode.java	Wed May 26 10:49:50 2010 +0900
@@ -31,7 +31,7 @@
 	}
 	
 	@Override public void mainLoop() {
-		me.mainLoop();
+		me.mainLoop(ml);
 	}
 	public void setMetaEngine(MetaEngine me) {
 		this.me = me; 
--- a/src/fdl/test/debug2/MetaProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/debug2/MetaProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -24,10 +24,10 @@
 		ml.out(TupleId.BODY.id, ByteBuffer.wrap("dummy".getBytes()));
 	}
 
-	public void mainLoop() {
+	public void mainLoop(MetaLinda ml) {
 		initPoller();
 		while (np.running) {
-			np.ml.sync();
+			np.ml.sync(0);
 		}
 		Debug.print("Terminated" + np.nodeId
 				+ " replies=" + np.ml.replies.size()
--- a/src/fdl/test/metaTransfer/FDLServWithSend.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/metaTransfer/FDLServWithSend.java	Wed May 26 10:49:50 2010 +0900
@@ -15,9 +15,9 @@
 
 	@Override public void mainLoop() {
 		System.out.println("change mainloop");
-		MetaLinda ml = new MetaLinda(tupleSpace, this);
+		MetaLinda ml = new MetaLinda(this.tupleSpace,this);
 		MetaProtocolEngine mpe = new MetaProtocolEngine(ml,"MetaEngine", port1);
-		mpe.mainLoop();
+		mpe.mainLoop(ml);
 	}
 
 }
--- a/src/fdl/test/metaTransfer/MetaProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/metaTransfer/MetaProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -30,7 +30,7 @@
 		this.fdl1 = ml;
 	}
 
-	public void mainLoop(){
+	public void mainLoop(MetaLinda ml){
 		boolean connect = true;
 		System.out.println("MetaEngine Start");
 		while(connect){
@@ -78,14 +78,14 @@
 				psx1.out(id,data2);
 				
 				System.out.println("IntData0 "+port1 +i);
-				fdl1.sync();
+				fdl1.sync(0);
 				if (count++>3) {
 					running = false;
 					break;
 				}
 				System.out.println("IntData1 "+port1 +i);
 			}
-			fdl1.sync();
+			fdl1.sync(0);
 		}
 		assertEquals(4,count);
 	}
--- a/src/fdl/test/metaTransfer/MetaProtocolEngine_not.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/metaTransfer/MetaProtocolEngine_not.java	Wed May 26 10:49:50 2010 +0900
@@ -54,7 +54,7 @@
 	}
 
 	
-	public void mainLoop() {
+	public void mainLoop(MetaLinda ml) {
 		System.out.println("MetaProtocolEngine Start");
 		fdlmeta = FederatedLinda.init();
 		if( port == 10002 ) {
--- a/src/fdl/test/metaTransfer/Ring/FDLServWithSend.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/metaTransfer/Ring/FDLServWithSend.java	Wed May 26 10:49:50 2010 +0900
@@ -14,9 +14,9 @@
 	
 	@Override public void mainLoop() {
 		System.out.println("change mainloop");
-		MetaLinda ml = new MetaLinda(tupleSpace, this);
+		MetaLinda ml = new MetaLinda(this.tupleSpace,this);
 		MetaProtocolEngine mpe = new MetaProtocolEngine(ml,"MetaEngine", port1, port1);
-		mpe.mainLoop();
+		mpe.mainLoop(ml);
 	}
 
 }
--- a/src/fdl/test/metaTransfer/Ring/MetaProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/metaTransfer/Ring/MetaProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -32,7 +32,7 @@
 		this.port = port;
 	}
 
-	public void mainLoop(){
+	public void mainLoop(MetaLinda ml){
 		boolean connect = true;
 		System.out.println("MetaEngine Start");
 		while(connect){
@@ -91,7 +91,7 @@
 				System.out.println("IntData1 "+port1 +i);
 				break;
 			}
-			fdl1.sync();
+			fdl1.sync(0);
 			}
 //		assertEquals(4,count);
 	}
--- a/src/fdl/test/topology/FDLindaNode.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/topology/FDLindaNode.java	Wed May 26 10:49:50 2010 +0900
@@ -31,7 +31,7 @@
 	}
 	
 	@Override public void mainLoop() {
-		me.mainLoop();
+		me.mainLoop(ml);
 	}
 	public void setMetaEngine(MetaEngine me) {
 		this.me = me; 
--- a/src/fdl/test/topology/MetaProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/topology/MetaProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -44,6 +44,7 @@
 		}
 		this.psxSendServers = new ArrayList<PSXLinda>();
 	}
+	public void mainLoop(MetaLinda ml) {}
 
 	public void mainLoop() {
 		psxLocal = fdlMeta;
--- a/src/fdl/test/topology/TopologyManagerEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/topology/TopologyManagerEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -36,6 +36,8 @@
 			this.nodes[i] = new NodeManager(fdlMeta, port, manageId);
 		}
 	}
+	
+	public void mainLoop(MetaLinda ml) {}
 
 	public void mainLoop() {
 		manager = fdlMeta;
--- a/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/transfer/cluster/FDLServWithSendMeta.java	Wed May 26 10:49:50 2010 +0900
@@ -28,7 +28,7 @@
 	@Override public void mainLoop() {
 		MetaLinda ml = new MetaLinda(tupleSpace, this);
 		MetaProtocolEngine mpe = new MetaProtocolEngine(ml, nextHost, chknum, bufsize, txt);
-		mpe.mainLoop();
+		mpe.mainLoop(ml);
 	}
 	
 	public static void main(String[] args){
--- a/src/fdl/test/transfer/cluster/MetaProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/transfer/cluster/MetaProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -41,7 +41,7 @@
 		this.txt = txt;
 	}
 
-	public void mainLoop(){
+	public void mainLoop(MetaLinda ml){
 		psxget = fdlmeta;
 		if (chknum == 1) {
 			try {
@@ -121,7 +121,7 @@
 				running = false;
 				break;
 			}
-			fdlmeta.sync();
+			fdlmeta.sync(0);
 		}
 	}
 
--- a/src/fdl/test/transfer/two/ProtocolEngine.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test/transfer/two/ProtocolEngine.java	Wed May 26 10:49:50 2010 +0900
@@ -43,7 +43,7 @@
 		send.putInt(12);
 		send.flip();
 		psx2.out(id, send);
-		psx2.sync();
+		psx2.sync(0);
 	}
 	
 
--- a/src/fdl/test2/TestRing.java	Wed May 26 08:56:24 2010 +0900
+++ b/src/fdl/test2/TestRing.java	Wed May 26 10:49:50 2010 +0900
@@ -36,7 +36,7 @@
 
 		psx.out(1,data);
 		while(!r.ready()){
-		psx.sync();
+		psx.sync(0);
 		}
 		}
         br.close();