Mercurial > hg > FederatedLinda
diff src/fdl/test/debug/MetaProtocolEngine.java @ 91:4df1d50df52a
Ring: fdl.test.debug
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 16 Feb 2010 03:58:06 +0900 |
parents | 9cdc24bae625 |
children | 0ea086f0e96f |
line wrap: on
line diff
--- a/src/fdl/test/debug/MetaProtocolEngine.java Sat Feb 13 04:16:15 2010 +0900 +++ b/src/fdl/test/debug/MetaProtocolEngine.java Tue Feb 16 03:58:06 2010 +0900 @@ -68,7 +68,6 @@ private DocumentBuilderFactory dbFactory = null; private DocumentBuilder docBuilder = null; - protected Document document; public AcceptXMLCallback(int tid) { this.tid = tid; @@ -100,7 +99,7 @@ Element root = doc.getDocumentElement(); if(root.getTagName().equals("connections")) { - nodeId = new Integer(root.getAttribute("id")).intValue(); + nodeId = Integer.parseInt(root.getAttribute("id")); if (nodeId == 0) { ml.in(START, new StartCallback()); ml.in(DEBUGSTART, new DebugStartCallback()); @@ -111,14 +110,14 @@ Element host = (Element)connection.getElementsByTagName("host").item(0); Element port = (Element)connection.getElementsByTagName("port").item(0); Element t = (Element)connection.getElementsByTagName("tid").item(0); - int srcId = new Integer(connection.getAttribute("id")).intValue(); + int srcId = Integer.parseInt(connection.getAttribute("id")); String dstHostName = host.getTextContent(); - int dstPort = new Integer(port.getAttribute("id")).intValue(); - int dstId = new Integer(t.getAttribute("id")).intValue(); + int dstPort = Integer.parseInt(port.getAttribute("id")); + int dstId = Integer.parseInt(t.getAttribute("id")); try { PSXLindaImpl linda = (PSXLindaImpl) ml.open(dstHostName, dstPort); Routing r = new Routing(linda, dstId); - nodes.put(new Integer(srcId), r); + nodes.put(srcId, r); ml.in(srcId, new RoutingCallback(srcId, r)); } catch (IOException e) { e.printStackTrace(); @@ -130,13 +129,12 @@ NodeList routing = root.getElementsByTagName("source"); for (int i = 0; i < routing.getLength(); i++) { Element src = (Element) routing.item(i); - Integer srcId = new Integer(src.getAttribute("id")); + Integer srcId = Integer.parseInt(src.getAttribute("id")); Routing r = nodes.get(srcId); NodeList dest = src.getElementsByTagName("dest"); 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); + r.route.add(Integer.parseInt(dst.getAttribute("id"))); } } @@ -164,13 +162,13 @@ public void callback(ByteBuffer reply) { String str = new String(reply.array()); - + print("get message"); if (tid == TREETOP || tid == TREELEFT || tid == TREERIGHT) { ml.in(BODY); ml.out(BODY, reply); print("Update body"); } else if (str.equals("shutdown") && (tid == RINGLEFT || tid == RINGRIGHT)) { - print("get shutdown command"); + print("get shutdown command id: " + nodeId); if (nodeId != 0) { Routing r = null; if (tid == RINGLEFT) { @@ -178,25 +176,24 @@ } else if (tid == RINGRIGHT) { r = nodes.get(new Integer(RINGLEFT)); } + r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes())); print("out"); - PSXReply o = r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes())); - while (ml.fdl.qsize != 0) - ml.sync(1); + ml.fdl.queueExec(); print("sync"); - ((PSXLindaImpl) r.linda).close(); + } else { + print("shutdown reaches last node!"); } running = false; return; } else if (nodeId == 0 && tid == RINGLEFT) { relayCounter++; - print(new Integer(relayCounter).toString() + " relay"); + print("" + relayCounter + " relay"); if (relayCounter >= relayNum) { // 実験終了 endTime = new Date(); Double resultTime = new Double(((endTime.getTime() - startTime.getTime()) / (double)relayNum)); ByteBuffer data = ByteBuffer.wrap(resultTime.toString().getBytes()); manager.out(MANAGE, data); - //sendLocalHostName(); ml.in(tid, this); return; } @@ -214,17 +211,16 @@ } private class StartCallback implements PSXCallback { - public void callback(ByteBuffer reply) { Routing r; // 子があるならば、子にタプルを伝搬 - if (nodes.containsKey(new Integer(TREERIGHT))) { - r = nodes.get(new Integer(TREERIGHT)); + if (nodes.containsKey(TREERIGHT)) { + r = nodes.get(TREERIGHT); r.linda.out(r.dstId, reply); } - if (nodes.containsKey(new Integer(TREELEFT))) { - r = nodes.get(new Integer(TREELEFT)); + if (nodes.containsKey(TREELEFT)) { + r = nodes.get(TREELEFT); r.linda.out(r.dstId, reply); } ml.in(START, this); @@ -237,20 +233,17 @@ String[] commands = new String(reply.array()).split(","); String command = commands[0]; if (command.equals("relay")) { - relayNum = new Integer(commands[1]).intValue(); - relaySize = new Integer(commands[2]).intValue(); + relayNum = Integer.parseInt(commands[1]); + relaySize = Integer.parseInt(commands[2]); relayCounter = 0; - - print("relay num=" + new Integer(relayNum).toString() + " size=" + new Integer(relaySize).toString()); - - Routing r = nodes.get(new Integer(RINGRIGHT)); - + print("relay num=" + relayNum + " size=" + relaySize); + Routing r = nodes.get(RINGRIGHT); // 実験開始 startTime = new Date(); 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)); + Routing r = nodes.get(RINGRIGHT); r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes())); //running = false; } @@ -278,8 +271,9 @@ while (running) { ml.sync(); } - print("Terminated"); - + print("Terminated" + nodeId + + " replies=" + ml.replies.size() + + " qsize=" + ml.fdl.qsize); } protected void initPoller() { @@ -289,8 +283,7 @@ protected void sendLocalHostName() { // TopologyManager に自分のホストネームを送信して、起動を伝える - ByteBuffer local; - local = ByteBuffer.wrap((localHostName + ":" + new Integer(localPort).toString()).getBytes()); + ByteBuffer local = ByteBuffer.wrap((localHostName + ":" + localPort).getBytes()); manager.out(MANAGE, local); }