Mercurial > hg > FederatedLinda
changeset 89:b658ff1eb90f
MetaLinda.java sync() bug fix
author | one |
---|---|
date | Thu, 11 Feb 2010 16:26:04 +0900 |
parents | 5d1189e9e420 |
children | 9cdc24bae625 |
files | src/fdl/MetaLinda.java src/fdl/PSXLindaImpl.java src/fdl/test/debug/ConfigurationManagerEngine.java src/fdl/test/debug/MetaProtocolEngine.java |
diffstat | 4 files changed, 62 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fdl/MetaLinda.java Thu Feb 11 12:22:41 2010 +0900 +++ b/src/fdl/MetaLinda.java Thu Feb 11 16:26:04 2010 +0900 @@ -114,17 +114,22 @@ * rest is checked on the next sync call including * the recursive case. */ - int count = replies.size(); - while(count-->0) { - MetaReply r = replies.poll(); - // previous call back may call this sync and make - // replies shorter. - if (r==null) break; - if (r.ready()) { - } else { - addReply(r); + boolean hasNewReply; + do { + hasNewReply = false; + int count = replies.size(); + while (count-->0) { + MetaReply r = replies.poll(); + // previous call back may call this sync and make + // replies shorter. + if (r==null) break; + if (r.ready()) { + hasNewReply = true; + } else { + addReply(r); + } } - } + } while (hasNewReply); return 0; }
--- a/src/fdl/PSXLindaImpl.java Thu Feb 11 12:22:41 2010 +0900 +++ b/src/fdl/PSXLindaImpl.java Thu Feb 11 16:26:04 2010 +0900 @@ -180,6 +180,7 @@ public void send(ByteBuffer command, ByteBuffer data) { PSX.send(socketChannel, command, data); + fdl.log(Level.INFO,"Linda client sent data to "+socketChannel + " " + new String(data.array())); }
--- a/src/fdl/test/debug/ConfigurationManagerEngine.java Thu Feb 11 12:22:41 2010 +0900 +++ b/src/fdl/test/debug/ConfigurationManagerEngine.java Thu Feb 11 16:26:04 2010 +0900 @@ -77,11 +77,26 @@ nodes[0].linda.out(START, ByteBuffer.wrap("test".getBytes())); // DebugRing 開始を通知 nodes[0].linda.out(DEBUGSTART, ByteBuffer.wrap("relay,10,1024".getBytes())); + ml.in(MANAGE, new ConfirmFinish()); } } } + private class ConfirmFinish implements PSXCallback { + public void callback(ByteBuffer reply) { + nodes[0].linda.out(DEBUGSTART, ByteBuffer.wrap("shutdown".getBytes())); + print("Finish token"); + try { + nodes[0].linda.sync(1); + } catch (IOException e) { + e.printStackTrace(); + } + running = false; + } + + } + public ConfigurationManagerEngine(MetaLinda metaLinda, int nodeNum) { // initialize this.ml = metaLinda;
--- 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(); } }