|
From: Jonathan L. <le...@us...> - 2006-12-05 03:19:07
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10918/src/edu/harvard/syrah/pyxida/nc Modified Files: NCManager.java Added Files: PingRequestMsg.java PingResponseMsg.java Log Message: moving ping to proxyping --- NEW FILE: PingResponseMsg.java --- package edu.harvard.syrah.pyxida.nc; import edu.harvard.syrah.pyxida.nc.lib.Coordinate; import edu.harvard.syrah.sbon.comm.AddressIF; import edu.harvard.syrah.sbon.comm.obj.ObjMessage; /** * Response to ProxyPingRequestMsg. */ public class ProxyPingResponseMsg extends ObjMessage { static final long serialVersionUID = 1000000001L; final Coordinate remoteCoordinate; final double remoteError; final long remoteAge; final double latency; public ProxyPingResponseMsg (Coordinate _remoteCoordinate, double _remoteError, long _remoteAge, double _latency) { remoteCoordinate = _remoteCoordinate; remoteError = _remoteError; remoteAge = _remoteAge; latency = _latency; } } --- NEW FILE: PingRequestMsg.java --- package edu.harvard.syrah.pyxida.nc; import edu.harvard.syrah.sbon.comm.obj.ObjMessage; import edu.harvard.syrah.sbon.comm.AddressIF; /** * Requests the receiving node's current coordinate, confidence * and last update time. */ public class ProxyPingRequestMsg extends ObjMessage { static final long serialVersionUID = 1000000001L; final AddressIF target; /** * Creates a ProxyPingRequestMsg */ public ProxyPingRequestMsg (AddressIF _target) { target = _target; } } Index: NCManager.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc/NCManager.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** NCManager.java 4 Dec 2006 17:15:48 -0000 1.19 --- NCManager.java 5 Dec 2006 03:19:06 -0000 1.20 *************** *** 18,23 **** import edu.harvard.syrah.sbon.comm.obj. *; - //MEDTODO add proxy coordinates - /** * Manages the local and proxy coordinates. --- 18,21 ---- *************** *** 30,34 **** // Number of dimensions ! static final int NC_NUM_DIMS = Integer.parseInt(Config.getProperty("pyxida.dimensions", "5")); public static final boolean WATCH_NEIGHBORS = Boolean.parseBoolean(Config.getConfigProps().getProperty("pyxida.ncmanager.watch_neighbors", "false")); --- 28,32 ---- // Number of dimensions ! public static final int NC_NUM_DIMS = Integer.parseInt(Config.getProperty("pyxida.dimensions", "5")); public static final boolean WATCH_NEIGHBORS = Boolean.parseBoolean(Config.getConfigProps().getProperty("pyxida.ncmanager.watch_neighbors", "false")); *************** *** 57,61 **** private PingManager pingManager = null; ! private Set<ProxyClient> proxyClients = new HashSet<ProxyClient>(); final ObjCommIF comm; --- 55,60 ---- private PingManager pingManager = null; ! private Map<AddressIF,ProxyClient> addr2proxyClient = ! new HashMap<AddressIF,ProxyClient>(); final ObjCommIF comm; *************** *** 85,88 **** --- 84,88 ---- comm.registerMessageCB(GossipRequestMsg.class, new GossipHandler()); comm.registerMessageCB(CoordRequestMsg.class, new CoordHandler()); + comm.registerMessageCB(PingRequestMsg.class, new PingHandler()); upNeighbors = new HashSet<AddressIF>(); *************** *** 109,115 **** localNC.init(); - // MEDTODO Start periodic cleaner - //neighborClean(); - cbDone.callOK(); break; --- 109,112 ---- *************** *** 131,145 **** /** - * Not implemented yet. */ ! public void createProxyCoord(AddressIF remoteNode, long lease) { ! // LOWTODO } /** ! * Not implemented yet. */ ! public void destroyProxyCoord(AddressIF remoteNode) { ! // LOWTODO } --- 128,166 ---- /** */ ! public boolean createProxyCoord(AddressIF remoteNode, long lease) { ! if (!Pyxida.USE_ICMP) return false; ! if (addr2proxyClient.containsKey(remoteNode)) { ! log.debug("Not creating proxy coord for "+remoteNode+ ! " because one already exists"); ! return false; ! } ! ProxyClient client = new ProxyClient(remoteNode,lease); ! addr2proxyClient.put(remoteNode,client); ! return true; } /** ! * @return Coordinate for this remoteNode if we are ! * storing one. */ ! public Coordinate getProxyCoord(AddressIF remoteNode) { ! ProxyClient proxyCoord = addr2proxyClient.get(remoteNode); ! if (proxyCoord == null) { ! log.debug("No proxy coord for "+remoteNode+" found"); ! } ! return proxyCoord.nc.getSystemCoords(); ! } ! ! /** ! * @return true if proxy coordinate existed for remoteNode ! */ ! public boolean destroyProxyCoord(AddressIF remoteNode) { ! ProxyClient proxyCoord = addr2proxyClient.remove(remoteNode); ! if (proxyCoord == null) { ! log.debug("No proxy coord for "+remoteNode+" found"); ! return false; ! } ! return true; } *************** *** 159,170 **** /** - * Not implemented yet. - */ - public Coordinate getProxyCoord(AddressIF remoteNode) { - // LOWTODO - return null; - } - - /** * Fetch coordinate from remote node. */ --- 180,183 ---- *************** *** 312,315 **** --- 325,358 ---- } + class ProxyPingHandler extends ResponseObjCommCB<ProxyPingRequestMsg> { + public void cb(final CBResult result, final ProxyPingRequestMsg msg, + final AddressIF remoteAddr, + final Long ts, final CB1<Boolean> cbHandled) { + log.debug("in ProxyPingHandler remoteAddr="+remoteAddr); + pingManager.addPingRequest(msg.target, new CB1<Double>() { + protected void cb(CBResult pingResult, Double latency) { + switch (pingResult.state) { + case OK: { + log.debug("latency to "+msg.target+"="+latency); + sendResponseMessage + ("Ping", remoteAddr, + new ProxyPingResponseMsg(latency), msg.getMsgId(), + null, cbHandled); + break; + } + case TIMEOUT: + case ERROR: { + sendResponseMessage + ("Ping", remoteAddr, + new PingResponseMsg(0), msg.getMsgId(), + "Ping to "+msg.target+" failed", cbHandled); + break; + } + } + } + }); + } + } + AddressIF getUpNeighbor() { if (upNeighbors.size() == 0 && pendingNeighbors.size() == 0) { *************** *** 451,461 **** double rtt = (System.nanoTime() - sendStamp) / 1000000d; - // LOWTODO can use time of this instead of ping time - // if we want to not use jpcap pings - // (running not at root) - // - // However PRP not sure what the best way is to integrate this... - // Ideally, all latency measurements should be done by the ping manager...? - switch (result.state) { case OK: { --- 494,497 ---- *************** *** 477,485 **** log.debug("latency of "+latency+" to "+neighbor); - // MEDTODO convert nclib to use floats - // - // JTLTODO: why do you want to use floats and not double? won't we run into - // accuracy problems? - //long lat_ms = (long) Math.round(latency); long curr_time = System.currentTimeMillis(); --- 513,516 ---- *************** *** 558,561 **** --- 589,598 ---- long lease; + public boolean equals(ProxyClient c) { + if (addr.equals(c.addr)) + return true; + return false; + } + void update() { registerTimer(); *************** *** 564,570 **** // ask him to ping our address // and tell us about him ! ! // update our coordinate ! } --- 601,630 ---- // ask him to ping our address // and tell us about him ! ProxyPingRequestMsg msg = new ProxyPingRequestMsg(addr); ! comm.sendRequestMessage ! (msg, neighbor, ! new ObjCommRRCB<ProxyPingResponseMsg>() { ! protected void cb(CBResult result, ! final ProxyPingResponseMsg responseMsg, ! AddressIF remoteAddr, Long ts) { ! switch (result.state) { ! case OK: { ! log.debug("proxyping response from "+neighbor); ! nc.processSample(neighbor, responseMsg.remoteCoordinate, ! responseMsg.remoteError, latency, ! responseMsg.remoteAge, ! curr_time, true); ! log.debug("update: "+nc); ! addUpNeighbor(neighbor); ! break; ! } ! case TIMEOUT: ! case ERROR: { ! log.warn("proxyping response to "+neighbor+" failed"); ! addDownNeighbor(neighbor); ! } ! } ! } ! }); } |