|
From: Peter P. <pr...@us...> - 2006-11-27 16:25:12
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22326/src/edu/harvard/syrah/pyxida/nc Modified Files: NCManager.java Log Message: Fixed problem with missing port numbers Index: NCManager.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc/NCManager.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NCManager.java 27 Nov 2006 15:57:22 -0000 1.7 --- NCManager.java 27 Nov 2006 16:24:59 -0000 1.8 *************** *** 1,14 **** ! package edu.harvard.syrah.pyxida.nc; ! import java.util.Arrays; ! import java.util.HashSet; ! import java.util.ArrayList; ! import java.util.Map; ! import java.util.HashMap; ! import java.util.Set; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.pyxida.nc.lib.Coordinate; - import edu.harvard.syrah.pyxida.*; import edu.harvard.syrah.pyxida.nc.lib.NCClient; import edu.harvard.syrah.pyxida.ping.PingManager; --- 1,9 ---- ! package edu.harvard.syrah.pyxida.nc; ! import java.util.*; import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.pyxida.Pyxida; import edu.harvard.syrah.pyxida.nc.lib.Coordinate; import edu.harvard.syrah.pyxida.nc.lib.NCClient; import edu.harvard.syrah.pyxida.ping.PingManager; *************** *** 25,29 **** import edu.harvard.syrah.sbon.comm.obj.ObjMessageIF; ! // MEDTODO add proxy coordinates /** --- 20,24 ---- import edu.harvard.syrah.sbon.comm.obj.ObjMessageIF; ! //MEDTODO add proxy coordinates /** *************** *** 38,42 **** // Number of dimensions private static final int NC_NUM_DIMS = Integer.parseInt(Config.getProperty("pyxida.dimensions", "5")); ! // Height is set within NCClient and is the "last dimension" // of the coordinates array. --- 33,37 ---- // Number of dimensions private static final int NC_NUM_DIMS = Integer.parseInt(Config.getProperty("pyxida.dimensions", "5")); ! // Height is set within NCClient and is the "last dimension" // of the coordinates array. *************** *** 46,61 **** // JTLTODO: You need to test the regex below. It should work ! private String bootstrapList[] = Config.getProperty("pyxida.bootstraplist", "glenora.eecs.harvard.edu, sb01.eecs.harvard.edu, sb02.eecs.harvard.edu, sb10.eecs.harvard.edu, sb11.eecs.harvard.edu").split("[,\\s]"); ! /** ! * Time between gossip messages to coordinate neighbors. ! * Default is 10 seconds. ! */ public static final long UPDATE_DELAY = 10 * 1000; ! /** ! * Default lifetime that proxy coordinates are managed for. ! * Set to one hour. ! */ public static final long DEFAULT_PROXY_LEASE = 3600 * 1000; --- 41,56 ---- // JTLTODO: You need to test the regex below. It should work ! private String bootstrapList[] = Config.getProperty("pyxida.bootstraplist", "glenora.eecs.harvard.edu sb01.eecs.harvard.edu sb02.eecs.harvard.edu sb10.eecs.harvard.edu sb11.eecs.harvard.edu").split("[\\s]"); ! /** ! * Time between gossip messages to coordinate neighbors. ! * Default is 10 seconds. ! */ public static final long UPDATE_DELAY = 10 * 1000; ! /** ! * Default lifetime that proxy coordinates are managed for. ! * Set to one hour. ! */ public static final long DEFAULT_PROXY_LEASE = 3600 * 1000; *************** *** 67,77 **** final CoordClient localNC; ! Map<AddressIF,Long> neighbor2age; ! ArrayList<AddressIF> neighbors; ! /** ! * Create a coordinate manager. ! * Does not block. ! */ public NCManager(ObjCommIF _comm, PingManager pingManager) { comm = _comm; --- 62,72 ---- final CoordClient localNC; ! Map<AddressIF,Long> neighbor2age; ! ArrayList<AddressIF> neighbors; ! /** ! * Create a coordinate manager. ! * Does not block. ! */ public NCManager(ObjCommIF _comm, PingManager pingManager) { comm = _comm; *************** *** 81,89 **** } ! /** ! * Asynchronous initialization of coordinate manager. ! * Resolves bootstrap neighbors and starts gossip for local coordinate. ! * Starts listening for gossip messages. ! */ public void init(final CB0 cbDone) { comm.registerMessageCB(GossipRequestMsg.class, new GossipHandler()); --- 76,84 ---- } ! /** ! * Asynchronous initialization of coordinate manager. ! * Resolves bootstrap neighbors and starts gossip for local coordinate. ! * Starts listening for gossip messages. ! */ public void init(final CB0 cbDone) { comm.registerMessageCB(GossipRequestMsg.class, new GossipHandler()); *************** *** 92,100 **** neighbors = new ArrayList<AddressIF>(); ! AddressFactory.createResolved(Arrays.asList(bootstrapList), new CB1<Map<String, AddressIF>>() { protected void cb(CBResult result, Map<String, AddressIF> addrMap) { switch (result.state) { case OK: { for (String remoteNode : addrMap.keySet()) { AddressIF remoteAddr = addrMap.get(remoteNode); addGossipNode(remoteAddr); --- 87,97 ---- neighbors = new ArrayList<AddressIF>(); ! log.debug("Resolving bootstrap list"); ! AddressFactory.createResolved(Arrays.asList(bootstrapList), Pyxida.COMM_PORT, new CB1<Map<String, AddressIF>>() { protected void cb(CBResult result, Map<String, AddressIF> addrMap) { switch (result.state) { case OK: { for (String remoteNode : addrMap.keySet()) { + log.debug("remoteNode='" + remoteNode + "'"); AddressIF remoteAddr = addrMap.get(remoteNode); addGossipNode(remoteAddr); *************** *** 120,154 **** } ! /** ! * Not implemented yet. ! */ public void createProxyCoord(AddressIF remoteNode, long lease) { // LOWTODO } ! /** ! * Not implemented yet. ! */ public void destroyProxyCoord(AddressIF remoteNode) { // LOWTODO } ! /** ! * @return local coordinate ! */ public Coordinate getLocalCoord() { return localNC.nc.getSystemCoords(); } ! /** ! * @return local error ! */ public double getLocalError() { return localNC.nc.getSystemError(); } ! /** ! * Not implemented yet. ! */ public Coordinate getProxyCoord(AddressIF remoteNode) { // LOWTODO --- 117,151 ---- } ! /** ! * Not implemented yet. ! */ public void createProxyCoord(AddressIF remoteNode, long lease) { // LOWTODO } ! /** ! * Not implemented yet. ! */ public void destroyProxyCoord(AddressIF remoteNode) { // LOWTODO } ! /** ! * @return local coordinate ! */ public Coordinate getLocalCoord() { return localNC.nc.getSystemCoords(); } ! /** ! * @return local error ! */ public double getLocalError() { return localNC.nc.getSystemError(); } ! /** ! * Not implemented yet. ! */ public Coordinate getProxyCoord(AddressIF remoteNode) { // LOWTODO *************** *** 156,162 **** } ! /** ! * ! */ public double estimateRTT(AddressIF nodeA, AddressIF nodeB) { // TODO --- 153,159 ---- } ! /** ! * ! */ public double estimateRTT(AddressIF nodeA, AddressIF nodeB) { // TODO *************** *** 171,175 **** public void shutDown(DataOutputStream os) throws IOException { } ! */ abstract class ResponseObjCommCB<T extends ObjMessageIF> extends ObjCommCB<T> { --- 168,172 ---- public void shutDown(DataOutputStream os) throws IOException { } ! */ abstract class ResponseObjCommCB<T extends ObjMessageIF> extends ObjCommCB<T> { *************** *** 213,217 **** new GossipResponseMsg(localNC.nc.getSystemCoords(), localNC.nc.getSystemError(), localNC.nc.getAge(curr_time), getGossipNodes(msg.coordinate)), msg.getMsgId(), null, ! cbHandled); } --- 210,214 ---- new GossipResponseMsg(localNC.nc.getSystemCoords(), localNC.nc.getSystemError(), localNC.nc.getAge(curr_time), getGossipNodes(msg.coordinate)), msg.getMsgId(), null, ! cbHandled); } *************** *** 219,272 **** ! AddressIF getGossipNode() { ! if (neighbors.size() == 0) { ! log.warn("we are lonely and have no one to gossip with"); ! return null; ! } ! int index = Pyxida.random.nextInt(neighbors.size()); ! AddressIF node = neighbors.get(index); ! return node; ! } Set<AddressIF> getGossipNodes(Coordinate remoteCoord) { ! Set<AddressIF> nodes = new HashSet<AddressIF>(); ! // LOWTODO add option of loop here ! AddressIF node = getGossipNode(); ! if (node != null) { ! nodes.add(node); ! } ! return nodes; } void addGossipNodes(Set<AddressIF> nodes) { ! for (AddressIF node : nodes) { ! addGossipNode (node); ! } } void addGossipNode(AddressIF node) { ! long curr_time = System.currentTimeMillis(); ! Long expiry = neighbor2age.get(node); ! if (expiry != null) { ! log.debug ("gossip already knew node "+node); ! long old_time = expiry.longValue(); ! expiry = new Long (curr_time); ! ! expiry = neighbor2age.get(node); ! long new_time = expiry.longValue(); ! log.debug ("old_time "+old_time+" new "+new_time); ! return; ! } ! neighbors.add(node); ! neighbor2age.put(node,curr_time); ! log.debug ("gossip added new neighbor "+node); } class CoordClient { final NCClient<AddressIF> nc; ! final CB0 updateCB; public CoordClient() { --- 216,269 ---- ! AddressIF getGossipNode() { ! if (neighbors.size() == 0) { ! log.warn("we are lonely and have no one to gossip with"); ! return null; ! } ! int index = Pyxida.random.nextInt(neighbors.size()); ! AddressIF node = neighbors.get(index); ! return node; ! } Set<AddressIF> getGossipNodes(Coordinate remoteCoord) { ! Set<AddressIF> nodes = new HashSet<AddressIF>(); ! // LOWTODO add option of loop here ! AddressIF node = getGossipNode(); ! if (node != null) { ! nodes.add(node); ! } ! return nodes; } void addGossipNodes(Set<AddressIF> nodes) { ! for (AddressIF node : nodes) { ! addGossipNode (node); ! } } void addGossipNode(AddressIF node) { ! long curr_time = System.currentTimeMillis(); ! Long expiry = neighbor2age.get(node); ! if (expiry != null) { ! log.debug ("gossip already knew node "+node); ! long old_time = expiry.longValue(); ! expiry = new Long (curr_time); ! expiry = neighbor2age.get(node); ! long new_time = expiry.longValue(); ! log.debug ("old_time "+old_time+" new "+new_time); ! ! return; ! } ! neighbors.add(node); ! neighbor2age.put(node,curr_time); ! log.debug ("gossip added new neighbor "+node); } class CoordClient { final NCClient<AddressIF> nc; ! final CB0 updateCB; public CoordClient() { *************** *** 274,298 **** updateCB = new CB0() { ! protected void cb(CBResult result) { ! update(); ! } ! }; } ! void registerTimer () { ! // LOWTODO adaptive delay ! double rnd = Pyxida.random.nextGaussian(); ! long delay = UPDATE_DELAY + (long)(1000 * rnd); ! log.debug ("setting timer to "+delay); ! EventLoop.get().registerTimerCB(delay, updateCB); ! } public void init() { ! registerTimer(); } void update() { ! registerTimer(); final AddressIF neighbor = pickGossipNode(); --- 271,296 ---- updateCB = new CB0() { ! protected void cb(CBResult result) { ! update(); ! } ! }; } ! void registerTimer () { ! // LOWTODO adaptive delay ! double rnd = Pyxida.random.nextGaussian(); ! long delay = UPDATE_DELAY + (long)(1000 * rnd); log.debug("Initialising the ping manager..."); ! ! log.debug ("setting timer to "+delay); ! EventLoop.get().registerTimerCB(delay, updateCB); ! } public void init() { ! registerTimer(); } void update() { ! registerTimer(); final AddressIF neighbor = pickGossipNode(); *************** *** 374,379 **** void update() { ! registerTimer(); ! final AddressIF neighbor = pickGossipNode(); // ask him to ping our address --- 372,377 ---- void update() { ! registerTimer(); ! final AddressIF neighbor = pickGossipNode(); // ask him to ping our address |