Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3630/src/edu/harvard/syrah/pyxida/nc
Modified Files:
NCManager.java
Added Files:
GossipRequestMsg.java GossipResponseMsg.java
Log Message:
objComm is looking for SBON code :(
Index: NCManager.java
===================================================================
RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/nc/NCManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** NCManager.java 21 Nov 2006 21:14:59 -0000 1.1
--- NCManager.java 25 Nov 2006 21:39:59 -0000 1.2
***************
*** 4,11 ****
--- 4,17 ----
import java.util.Set;
+ import edu.harvard.syrah.pyxida.nc.lib.*;
import edu.harvard.syrah.prp.Log;
import edu.harvard.syrah.pyxida.nc.lib.NCClient;
import edu.harvard.syrah.pyxida.ping.PingManager;
import edu.harvard.syrah.sbon.comm.AddressIF;
+ import edu.harvard.syrah.sbon.comm.obj.*;
+ import edu.harvard.syrah.sbon.async.*;
+ import edu.harvard.syrah.sbon.async.CallbacksIF.*;
+
+ // TODO add proxy coordinates
public class NCManager {
***************
*** 13,31 ****
// TODO read from config file
! private static final int NC_NUM_DIMS = 3;
private PingManager pingManager = null;
private Set<NCClient<AddressIF>> ncClients = new HashSet<NCClient<AddressIF>>();
! public NCManager(PingManager pingManager) {
! this.pingManager = pingManager;
! }
public void init() {
! // Initialise the local coord first
! NCClient<AddressIF> localNCClient = new NCClient<AddressIF>(NC_NUM_DIMS);
}
}
--- 19,102 ----
// TODO read from config file
! private static final int NC_NUM_DIMS = 5;
! // Height is set within NCClient and is the "last dimension"
! // of the coordinates array.
! // Thus, setting this to 5 is 4d+height if height is in use.
! // This allows the size on the wire to remain constant
! // which is important for Azureus integration.
private PingManager pingManager = null;
private Set<NCClient<AddressIF>> ncClients = new HashSet<NCClient<AddressIF>>();
+
+ final ObjCommIF comm;
+ final NCClient<AddressIF> localNCClient;
! public NCManager(ObjCommIF _comm, PingManager pingManager) {
! comm = _comm;
! this.pingManager = pingManager;
! // Initialise the local coord first
! localNCClient = new NCClient<AddressIF>(NC_NUM_DIMS);
!
! }
public void init() {
! comm.registerMessageCB(GossipRequestMsg.class, new GossipHandler());
! // TODO read in list of bootstrap neighbors from config file
!
! // TODO create timer to ping neighbors
! // and/or ask local client who it would like to ping
+ // Also ping for any proxy coordinates.
+
}
+ abstract class ResponseObjCommCB<T extends ObjMessageIF> extends ObjCommCB<T> {
+
+ void sendResponseMessage (final String handler, final AddressIF remoteAddr, final ObjMessage response, long requestMsgId, final String errorMessage, final CB1<Boolean> cbHandled) {
+
+ CBResult result = null;
+ if (errorMessage != null) {
+ log.debug(handler+ " :"+errorMessage);
+ result = CBResult.ERROR(errorMessage);
+ } else {
+ result = CBResult.OK();
+ }
+
+ comm.sendResponseMessage(response, remoteAddr, requestMsgId, new CB0() {
+ protected void cb(CBResult sendResult) {
+ switch (sendResult.state) {
+ case TIMEOUT:
+ case ERROR: {
+ log.warn(handler+": "+sendResult.what);
+ return;
+ }
+ }
+ }});
+ cbHandled.call(CBResult.OK(), true);
+ }
+ }
+
+ class GossipHandler extends ResponseObjCommCB<GossipRequestMsg> {
+
+ public void cb(CBResult result, GossipRequestMsg msg,
+ AddressIF remoteAddr, Long ts,
+ final CB1<Boolean> cbHandled) {
+ log.debug ("in GossipHandler cb: "+msg);
+
+ long curr_time = System.currentTimeMillis();
+
+ sendResponseMessage
+ ("Gossip", remoteAddr,
+ new GossipResponseMsg(localNCClient.getSystemCoords(), localNCClient.getSystemError(), localNCClient.getAge(curr_time), getGossipNodes(msg.coordinate)),
+ msg.getMsgId(), null, cbHandled);
+
+ }
+ }
+
+ Set<AddressIF> getGossipNodes (Coordinate remoteCoord) {
+ // TODO return coordinates, possibly based on this guy's coordinate
+ return null;
+ }
+
}
--- NEW FILE: GossipResponseMsg.java ---
package edu.harvard.syrah.pyxida.nc;
import java.util.Set;
import edu.harvard.syrah.sbon.comm.obj.ObjMessage;
import edu.harvard.syrah.pyxida.nc.lib.*;
import edu.harvard.syrah.prp.Log;
import edu.harvard.syrah.sbon.comm.AddressIF;
/**
* Response to GossipRequestMsg.
* Responds with the receiving node's current coordinate, confidence
* and last update time.
*/
public class GossipResponseMsg extends ObjMessage {
static final long serialVersionUID = 1000000001L;
final Coordinate remoteCoordinate;
final double remoteError;
final long remoteAge;
final Set<AddressIF> nodes;
public GossipResponseMsg (Coordinate _remoteCoordinate, double _remoteError, long _remoteAge,
Set<AddressIF> _nodes) {
remoteCoordinate = _remoteCoordinate;
remoteError = _remoteError;
remoteAge = _remoteAge;
nodes = _nodes;
}
}
--- NEW FILE: GossipRequestMsg.java ---
package edu.harvard.syrah.pyxida.nc;
import java.util.Set;
import edu.harvard.syrah.sbon.comm.obj.ObjMessage;
import edu.harvard.syrah.pyxida.nc.lib.*;
import edu.harvard.syrah.prp.Log;
import edu.harvard.syrah.sbon.comm.AddressIF;
/**
* Requests the receiving node's current coordinate, confidence
* and last update time.
*/
public class GossipRequestMsg extends ObjMessage {
static final long serialVersionUID = 1000000001L;
final Coordinate coordinate;
final Set<AddressIF> nodes;
/**
* Creates a GossipRequestMsg
* @param nodes
* set of nodes sender is gossipping to receiver
*/
public GossipRequestMsg (Coordinate _coordinate, Set<AddressIF> _nodes) {
coordinate = _coordinate;
nodes = _nodes;
}
}
|