|
From: Jonathan L. <le...@us...> - 2007-01-02 21:41:37
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25332/src/edu/harvard/syrah/pyxida/nc Modified Files: NCManager.java Log Message: stuck with passing arguments via XML/RPC Index: NCManager.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc/NCManager.java,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** NCManager.java 29 Dec 2006 10:21:35 -0000 1.28 --- NCManager.java 2 Jan 2007 21:41:34 -0000 1.29 *************** *** 224,236 **** void getRemoteOrLocalCoordinate (final AddressIF node, final Barrier barrier, ! final List<Coordinate> coordList, ! final CB2<Double,String> cbDistance) { ! if (node.equals(comm.getLocalAddress())) { ! coordList.add(getLocalCoord()); return; } ProxyClient proxyCoord = addr2proxyClient.get(node); if (proxyCoord != null) { ! coordList.add(proxyCoord.nc.getSystemCoords()); return; } --- 224,237 ---- void getRemoteOrLocalCoordinate (final AddressIF node, final Barrier barrier, ! final Map<AddressIF,Coordinate> addr2coord, ! final StringBuffer errorBuffer) { ! ! if (node.equals(comm.getLocalAddress())) { ! addr2coord.put(node,getLocalCoord()); return; } ProxyClient proxyCoord = addr2proxyClient.get(node); if (proxyCoord != null) { ! addr2coord.put(node,proxyCoord.nc.getSystemCoords()); return; } *************** *** 245,250 **** case OK: { log.debug("received coord back from "+node); ! coordList.add(resp.coord); ! barrier.join(); break; } --- 246,250 ---- case OK: { log.debug("received coord back from "+node); ! addr2coord.put(node,resp.coord); break; } *************** *** 254,270 **** +" failed:"+ result.toString(); log.warn(error); ! // TODO ! // Test to see if this callback has already errored ! // due to the other call ! cbDistance.call(result, new Double(0), error); ! // Remove the barrier to clear up state ! barrier.remove(); } } } }); } /** * Fetches coordinates from two nodes and returns --- 254,289 ---- +" failed:"+ result.toString(); log.warn(error); ! if (errorBuffer.length() != 0) { ! errorBuffer.append("\n"); ! } ! errorBuffer.append(error); ! // Remove the barrier to clear up state ! //barrier.remove(); ! break; } } + barrier.join(); + } + }); + } + + public void getRemoteCoords(final List<AddressIF> nodes, + final CB2<Map<AddressIF,Coordinate>,String> cbCoords) { + final Barrier barrier = new Barrier(true); + final Map<AddressIF,Coordinate> addr2coord = new HashMap<AddressIF,Coordinate>(); + final StringBuffer errorBuffer = new StringBuffer(); + for (AddressIF addr : nodes) { + getRemoteOrLocalCoordinate(addr,barrier,addr2coord, errorBuffer); + } + EventLoop.get().registerTimerCB(barrier, new CB0() { + protected void cb(CBResult result) { + String errorString = new String (errorBuffer); + cbCoords.call(CBResult.OK(),addr2coord, errorString); } }); } + /** * Fetches coordinates from two nodes and returns *************** *** 272,276 **** */ public void estimateRTT(final AddressIF nodeA, final AddressIF nodeB, ! final CB2<Double,String> cbDistance) { log.debug ("estimateRTT a="+nodeA+" b="+nodeB); --- 291,295 ---- */ public void estimateRTT(final AddressIF nodeA, final AddressIF nodeB, ! final CB1<Double> cbDistance) { log.debug ("estimateRTT a="+nodeA+" b="+nodeB); *************** *** 278,299 **** // to fork, then the barrier CB will be executed immediately. final Barrier barrier = new Barrier(true); ! final List<Coordinate> coordList = new ArrayList<Coordinate>(); ! getRemoteOrLocalCoordinate(nodeA,barrier,coordList,cbDistance); ! getRemoteOrLocalCoordinate(nodeB,barrier,coordList,cbDistance); ! EventLoop.get().registerTimerCB(barrier, new CB0() { protected void cb(CBResult result) { - // after barrier is triggered - - // TODO test to see if an error condition in the fn - // has already called the callback, - // in which case we are done. ! // Otherwise, find the distance and return it to the caller ! double distance = coordList.get(0).distanceTo(coordList.get(1)); ! log.debug("distance= "+distance); ! cbDistance.call(CBResult.OK(), distance, "Success"); } --- 297,321 ---- // to fork, then the barrier CB will be executed immediately. final Barrier barrier = new Barrier(true); ! final Map<AddressIF,Coordinate> addr2coord = new HashMap<AddressIF,Coordinate>(); ! final StringBuffer errorBuffer = new StringBuffer(); ! getRemoteOrLocalCoordinate(nodeA,barrier,addr2coord, errorBuffer); ! getRemoteOrLocalCoordinate(nodeB,barrier,addr2coord, errorBuffer); EventLoop.get().registerTimerCB(barrier, new CB0() { protected void cb(CBResult result) { ! Coordinate coordA = addr2coord.get(nodeA); ! Coordinate coordB = addr2coord.get(nodeB); ! if (coordA != null && coordB != null) { ! ! double distance = coordA.distanceTo(coordB); ! log.debug("distance= "+distance); ! cbDistance.call(CBResult.OK(), distance); ! } else { ! String errorString = new String (errorBuffer); ! log.warn(errorString); ! cbDistance.call(CBResult.ERROR(errorString), new Double(0)); ! } } |