changeset 85:d0d8aeaebccf

add routing table
author one
date Mon, 08 Feb 2010 11:07:57 +0900
parents c0575f877591
children c0591636a71a
files src/fdl/test/debug/MetaProtocolEngine.java
diffstat 1 files changed, 35 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/fdl/test/debug/MetaProtocolEngine.java	Sun Feb 07 20:55:12 2010 +0900
+++ b/src/fdl/test/debug/MetaProtocolEngine.java	Mon Feb 08 11:07:57 2010 +0900
@@ -42,7 +42,7 @@
 	private boolean connected = false;
 	private boolean debugConnected = false;
 	private int nodeId;
-	private HashMap<Integer, Routing> nodes, debugNodes;
+	private HashMap<Integer, Routing> nodes;
 	
 	// Callback class
 	class AcceptXMLCallback implements PSXCallback {
@@ -96,38 +96,27 @@
 					try {
 						PSXLindaImpl linda = (PSXLindaImpl) ml.open(dstHostName, dstPort);
 						Routing r = new Routing(linda, dstId);
-						if (tid == MANAGE)
-							nodes.put(new Integer(srcId), r);
-						else if (tid == DEBUG)
-							debugNodes.put(new Integer(srcId), r);
-						// TODO: implements PSXCallback
-						ml.in(srcId);
+						nodes.put(new Integer(srcId), r);
+						ml.in(srcId, new RoutingCallback(srcId, r));
 					} catch (IOException e) {
 						e.printStackTrace();
 					}
 				}
 			} else if (root.getTagName().equals("routing")) {
 				print("Routing xml received!");
-				HashMap<Integer, Routing> n;
-				if (tid == MANAGE) {
-					n = nodes;
-				} else if (tid == DEBUG) {
-					n = debugNodes;
-				}
+
 				NodeList routing = root.getElementsByTagName("source");
 				for (int i = 0; i < routing.getLength(); i++) {
 					Element src = (Element) routing.item(i);
-					int srcId = new Integer(src.getAttribute("id"));
+					Integer srcId = new Integer(src.getAttribute("id"));
+					Routing r = nodes.get(srcId);
 					NodeList dest = src.getElementsByTagName("dest");
-					for (int j = 0; j < dest.getLength(); i++) {
-						Element dst = (Element) dest.item(i);
-						int dstId = new Integer(dst.getAttribute("id"));
+					for (int j = 0; j < dest.getLength(); j++) {
+						Element dst = (Element) dest.item(j);
+						Integer dstId = new Integer(dst.getAttribute("id"));
+						r.route.add(dstId);
 					}
-					print("");
 				}
-				//n.get(key);
-				
-				
 				
 			}
 			if (tid == MANAGE) connected = true;
@@ -141,6 +130,31 @@
 		
 	} 
 
+	private class RoutingCallback implements PSXCallback {
+		int tid;
+		Routing routing;
+		public RoutingCallback(int tid, Routing routing) {
+			this.tid = tid;
+			this.routing = routing;
+		} 
+		
+		public void callback(ByteBuffer reply) {
+			Iterator<Integer> it = routing.route.iterator();
+			while (it.hasNext()) {
+				Integer dstId = it.next();
+				Routing r = nodes.get(dstId);
+				r.linda.out(r.dstId, reply);
+				try {
+					r.linda.sync(1);
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+				ml.in(tid, this);
+			}
+		}
+		
+	}
+	
 	// Constructor
 	public MetaProtocolEngine(int port, MetaLinda ml, String managerHostName, int managerPort) {
 		this.ml = ml;
@@ -148,7 +162,6 @@
 		this.managerHostName = managerHostName;
 		this.managerPort = managerPort;
 		this.nodes = new HashMap<Integer, Routing>();
-		this.debugNodes = new HashMap<Integer, Routing>();
 		try {
 			this.localHostName = InetAddress.getLocalHost().getHostName();
 		} catch (UnknownHostException e) {
@@ -168,8 +181,6 @@
 	protected void initPoller() {
 		ml.in(MANAGE, new AcceptXMLCallback(MANAGE));
 		ml.in(DEBUG, new AcceptXMLCallback(DEBUG));
-		//ml.in(debugId, new ConnectServerCallback(debugId, psxDebugServers, null));
-		//ml.in(registId, new RegistServerCallback());
 	}
 	
 	protected void sendLocalHostName() {