# HG changeset patch # User one # Date 1265594877 -32400 # Node ID d0d8aeaebccff92cbb0b182b40b9e43fa4f12353 # Parent c0575f87759188a392b9b1a296dc33e1fc459230 add routing table diff -r c0575f877591 -r d0d8aeaebccf src/fdl/test/debug/MetaProtocolEngine.java --- 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 nodes, debugNodes; + private HashMap 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 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 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(); - this.debugNodes = new HashMap(); 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() {