changeset 107:3c532f771c56

fix comment
author one
date Sat, 29 May 2010 00:43:26 +0900
parents 342446d56b47
children 065450f32960
files src/fdl/test/TestTree.java
diffstat 1 files changed, 42 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/fdl/test/TestTree.java	Fri May 28 21:49:52 2010 +0900
+++ b/src/fdl/test/TestTree.java	Sat May 29 00:43:26 2010 +0900
@@ -37,7 +37,7 @@
 	/**
 	 * Global 
 	 */
-	public LinkedList<Thread> lindas = new LinkedList<Thread>();
+	public LinkedList<Thread> lindas = new LinkedList<Thread>(); // not used.
 	public  int id = 0;
 	public boolean debug = true;
 	
@@ -57,11 +57,8 @@
 	
 	/**
 	 * @author kono
-	 *
-	 */
-	/**
-	 * @author kono
-	 *
+	 *   Tuple transfer engine for a federated linda node   
+	 *   MetaLinda is passed to mainLoop in this class
 	 */
 	class TreeMetaProtocolEngine implements MetaEngine {
 		/**
@@ -75,6 +72,7 @@
 		int parentPort=0, leftPort=0, rightPort=0;
 		public int nodeId = 0;
 		public int nodePort  = 0;
+		public MetaLinda ml;
 
 		public TreeMetaProtocolEngine(int id, int port) {
 			nodeId = id;
@@ -84,13 +82,15 @@
 		/**
 		 *  Meta Engine Main Loop 
 		 */
-		public void mainLoop(final MetaLinda ml) {
+		public void mainLoop(MetaLinda meta) {
+			ml = meta;
 			/* handler of Server STOP command */
 			ml.in(PSX.META_STOP, new PSXCallback() {public void callback(ByteBuffer reply) {
 				running = false;}});
 			/* handler of Configuration */
 			ml.in(ConnectReuest, new PSXCallback() {public void callback(ByteBuffer reply) {
-				connectChildren(ml, reply);
+				configureConnection(reply);
+				engineStart();
 				}
 			});
 			while(running) {
@@ -99,10 +99,10 @@
 		}
 
 		/**
-		 * Configuration Packet Decoder for Tree Node
+		 * Configuration of node according to configuration packet
 		 * @param reply
 		 */
-		private void setHostPort(ByteBuffer reply) {
+		private void configureConnection(ByteBuffer reply) {
 			parentPort = reply.getInt();
 			leftPort = reply.getInt();
 			rightPort = reply.getInt();
@@ -112,17 +112,19 @@
 		}
 
 		/**
+		 * 
+		 * Open Inter-Server Connections and start tuple communication Engine
+		 * 
 		 *       parent
 		 *          |
 		 *       self = ml (Meta Linda Server)
 		 *       /    \
 		 *    left    right
 		 *    
-		 * @param ml        Meda Linda Server
-		 * @param reply     a contents of configuration packaet
+		 * @param ml        Meta Linda Server
+		 * @param reply     a contents of configuration packet
 		 */
-		private void connectChildren(final MetaLinda ml, ByteBuffer reply) {
-			setHostPort(reply);
+		private void engineStart() {
 			try {
 				/**
 				 * connect to neighbors
@@ -136,7 +138,7 @@
 				 *   Handle Downward tree walk
 				 */
 				ml.in(Down, new PSXCallback() {public void callback(ByteBuffer reply) {
-					ml.in(Down,this);
+					ml.in(Down,this); // start this call back again for next packet
 					if (left==null) {
 						if (debug) System.out.println("Reached in Leaf "+nodeId+" value = "+parentPort);
 						// Leaf case
@@ -146,7 +148,7 @@
 						ml.out(Up, answer);
 						return;
 					}
-					// Intermideate node
+					// intermediate node
 					if (debug) System.out.println("Pass it to the children from "+nodeId + " to "+ leftPort + " and " + rightPort + ".");
 					ByteBuffer copy = reply.duplicate();
 					left.out(Down, reply);
@@ -188,7 +190,7 @@
 			ByteBuffer out = ByteBuffer.allocate(10);
 			int value = leftWaiter.poll().getInt()+rightWaiter.poll().getInt();
 			if (parent!=null) {
-				// Intermedate node
+				// intermediate node
 				if (debug) System.out.println("Up the vluae "+value+" from "+nodeId);
 				out.putInt(value);
 				out.flip();
@@ -301,6 +303,9 @@
 		/**
 		 * Read connection p configuation in a ByteBuffer
 		 * @throws IOException
+		 * 
+		 * Easy binary format, we should use more general format such as
+		 * XML or messagePack.
 		 */
 		public void readConfigure() throws IOException {
 			int mode = 0;
@@ -308,7 +313,7 @@
 			while(config.hasRemaining()) {
 				int port = config.getInt();
 				if (mode==0) {
-					// Formar part
+					// Former part
 					// List of host and server name
 					if (port==HOST_LIST_END_MARK) { 
 						mode = 1;
@@ -331,6 +336,13 @@
 			}
 		}
 		
+		/**
+		 * Make a configuration packet for a federated linda node
+		 * @param host       No. of host to configure
+		 * @param parent
+		 * @param left
+		 * @param right
+		 */
 		private void connect(int host, int parent, int left, int right) {
 			PSXLinda p = psxs.get(host);
 			ByteBuffer out = ByteBuffer.allocate(4096);
@@ -386,6 +398,11 @@
 	}
 
 
+	/**
+	 * read null terminated String in ByteBuffer
+	 * @param reply
+	 * @return
+	 */
 	public String getString(ByteBuffer reply) {
 		byte c;
 		int position = reply.position();
@@ -399,13 +416,13 @@
 
 	}
 	
+	/**
+	 * put String in ByteBuffer with null
+	 * @param reply 
+	 * @param s
+	 */
 	public void putString(ByteBuffer reply,String s) {
 		reply.put(s.getBytes());
-//		
-//		for(int i=0; i<s.length(); i++) {
-//			char c= s.charAt(i);
-//			reply.putChar(c);
-//		}
 		reply.put((byte)0);
 	}
 
@@ -472,3 +489,5 @@
 		config.putInt(r);
 	}
 }
+
+/* end */