diff src/fdl/test/debug/MetaProtocolEngine.java @ 89:b658ff1eb90f

MetaLinda.java sync() bug fix
author one
date Thu, 11 Feb 2010 16:26:04 +0900 (2010-02-11)
parents 5d1189e9e420
children 9cdc24bae625
line wrap: on
line diff
--- a/src/fdl/test/debug/MetaProtocolEngine.java	Thu Feb 11 12:22:41 2010 +0900
+++ b/src/fdl/test/debug/MetaProtocolEngine.java	Thu Feb 11 16:26:04 2010 +0900
@@ -161,6 +161,8 @@
 		} 
 		
 		public void callback(ByteBuffer reply) {
+			String str = new String(reply.array());
+			
 			if (tid == TREETOP || tid == TREELEFT || tid == TREERIGHT) {
 				ml.in(BODY);
 				ml.out(BODY, reply);
@@ -169,10 +171,34 @@
 				relayCounter++;
 				print(new Integer(relayCounter).toString() + " relay");
 				if (relayCounter >= relayNum) {
+					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();
 			while (it.hasNext()) {
 				Integer dstId = it.next();
@@ -217,6 +243,10 @@
 				Routing r = nodes.get(new Integer(RINGRIGHT));
 				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;
 			}
 		}
 	}
@@ -276,6 +306,7 @@
 	
 	void print(String str) {
 		System.err.println("[DEBUG] " + localHostName + ": " + str);
+		System.err.flush();
 	}
 	
 }