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

MetaLinda.java sync() bug fix
author one
date Thu, 11 Feb 2010 16:26:04 +0900
parents 5d1189e9e420
children 9cdc24bae625
comparison
equal deleted inserted replaced
88:5d1189e9e420 89:b658ff1eb90f
159 this.routing = routing; 159 this.routing = routing;
160 ml.out(BODY, ByteBuffer.wrap("dummy".getBytes())); 160 ml.out(BODY, ByteBuffer.wrap("dummy".getBytes()));
161 } 161 }
162 162
163 public void callback(ByteBuffer reply) { 163 public void callback(ByteBuffer reply) {
164 String str = new String(reply.array());
165
164 if (tid == TREETOP || tid == TREELEFT || tid == TREERIGHT) { 166 if (tid == TREETOP || tid == TREELEFT || tid == TREERIGHT) {
165 ml.in(BODY); 167 ml.in(BODY);
166 ml.out(BODY, reply); 168 ml.out(BODY, reply);
167 print("Update body"); 169 print("Update body");
168 } else if (nodeId == 0 && tid == RINGLEFT) { 170 } else if (nodeId == 0 && tid == RINGLEFT) {
169 relayCounter++; 171 relayCounter++;
170 print(new Integer(relayCounter).toString() + " relay"); 172 print(new Integer(relayCounter).toString() + " relay");
171 if (relayCounter >= relayNum) { 173 if (relayCounter >= relayNum) {
174 sendLocalHostName();
172 ml.in(tid, this); 175 ml.in(tid, this);
173 return; 176 return;
174 } 177 }
175 } 178 } else if (str.equals("shutdown")) {
179 if (tid == RINGLEFT) {
180 Routing r = nodes.get(new Integer(RINGRIGHT));
181 r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
182 try {
183 r.linda.sync(1);
184 } catch (IOException e) {
185 e.printStackTrace();
186 }
187 running = false;
188 return;
189 } else if (tid == RINGRIGHT) {
190 Routing r = nodes.get(new Integer(RINGLEFT));
191 r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
192 try {
193 r.linda.sync(1);
194 } catch (IOException e) {
195 e.printStackTrace();
196 }
197 running = false;
198 return;
199 }
200 }
201
176 Iterator<Integer> it = routing.route.iterator(); 202 Iterator<Integer> it = routing.route.iterator();
177 while (it.hasNext()) { 203 while (it.hasNext()) {
178 Integer dstId = it.next(); 204 Integer dstId = it.next();
179 Routing r = nodes.get(dstId); 205 Routing r = nodes.get(dstId);
180 r.linda.out(r.dstId, reply); 206 r.linda.out(r.dstId, reply);
215 print("relay num=" + new Integer(relayNum).toString() + " size=" + new Integer(relaySize).toString()); 241 print("relay num=" + new Integer(relayNum).toString() + " size=" + new Integer(relaySize).toString());
216 242
217 Routing r = nodes.get(new Integer(RINGRIGHT)); 243 Routing r = nodes.get(new Integer(RINGRIGHT));
218 r.linda.out(r.dstId, ByteBuffer.wrap(new byte[relaySize])); 244 r.linda.out(r.dstId, ByteBuffer.wrap(new byte[relaySize]));
219 ml.in(DEBUGSTART, this); 245 ml.in(DEBUGSTART, this);
246 } else if (command.equals("shutdown")) {
247 Routing r = nodes.get(new Integer(RINGRIGHT));
248 r.linda.out(r.dstId, ByteBuffer.wrap("shutdown".getBytes()));
249 running = false;
220 } 250 }
221 } 251 }
222 } 252 }
223 253
224 // Constructor 254 // Constructor
274 return linda; 304 return linda;
275 } 305 }
276 306
277 void print(String str) { 307 void print(String str) {
278 System.err.println("[DEBUG] " + localHostName + ": " + str); 308 System.err.println("[DEBUG] " + localHostName + ": " + str);
309 System.err.flush();
279 } 310 }
280 311
281 } 312 }