[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla
LocationManager.java, 1.21, 1.22
Chien-Liang Fok
chien-liang at users.sourceforge.net
Mon May 1 09:09:03 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25666/edu/wustl/mobilab/agilla
Modified Files:
LocationManager.java
Log Message:
Added an expiration time to the Cluster and a periodic Timer to the directory that removes expired clusters.
Index: LocationManager.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/contrib/wustl/tools/java/edu/wustl/mobilab/agilla/LocationManager.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** LocationManager.java 23 Apr 2006 20:04:20 -0000 1.21
--- LocationManager.java 1 May 2006 16:09:01 -0000 1.22
***************
*** 47,51 ****
final static int QUERY_CHECK_INTERVAL = 5; // seconds
final static int QUERY_TIMEOUT = 5; // seconds
! final static int CH_UPDATE_INTERVAL = 10; // seconds
final static int BS_UPDATE_INTERVAL = 20; // seconds
final static int AGENT_INFO_TIMEOUT = 120; // seconds
--- 47,57 ----
final static int QUERY_CHECK_INTERVAL = 5; // seconds
final static int QUERY_TIMEOUT = 5; // seconds
!
! /**
! * This is the period at which cluster heads are expected to update
! * the base station letting the base station know they still exist.
! */
! final static int CH_UPDATE_INTERVAL = 15; // seconds
!
final static int BS_UPDATE_INTERVAL = 20; // seconds
final static int AGENT_INFO_TIMEOUT = 120; // seconds
***************
*** 258,261 ****
--- 264,272 ----
private Vector<AgentInfo> agent_list;
private double expiry_time;
+
+ /**
+ * The time at which the last heartbeat was heard.
+ */
+ private long timestamp = (new Date()).getTime(); // added by liang
Cluster(){
***************
*** 457,461 ****
}
! }
class ClusterSet
--- 468,494 ----
}
! /**
! * Updates the timestamp to the current time. This is used to determine when to
! * remove a cluster from the Directory.
! *
! * <p>Added by Liang Fok
! */
! public void updateTimestamp() {
! timestamp = (new Date()).getTime();
! }
!
! /**
! * Determines whether this cluster has expired. A cluster expires when it
! * does not receive a beacon for two CH_UPDATE_INTERVAL periods.
! *
! * <p>Added by Liang Fok
! *
! * @return true if this cluster is expired.
! */
! public boolean isExpired() {
! return (new Date()).getTime() - timestamp > CH_UPDATE_INTERVAL*2*1000;
! }
!
! } // Cluster
class ClusterSet
***************
*** 499,502 ****
--- 532,536 ----
cluster.setBoundingBox(cl.getBoundingBox());
cluster.setExpiryTime(cl.getExpiryTime());
+ cluster.updateTimestamp(); // update the time at which the last beacon was received
return cluster;
}
***************
*** 598,601 ****
--- 632,658 ----
throw new IllegalAccessException("ClusterSet:deleteCluster() ERROR! Could not find cluster with id " + chId);
}
+
+ /**
+ * Goes through the clusters and finds those that are expired.
+ *
+ * <p>Added by Liang Fok
+ *
+ * @return a vector containing the cluster head IDs of the clusters that
+ * are expired.
+ */
+ public Vector<Integer> getExpiredClusters()
+ {
+ Vector<Integer> result = new Vector<Integer>();
+ for(int i = 0; i < clusters.size(); i++)
+ {
+ Cluster cluster = clusters.get(i);
+ if (cluster.isExpired())
+ {
+ //print("Cluster " + cluster.getId() + " is expired.");
+ result.add(new Integer(cluster.getId()));
+ }
+ }
+ return result;
+ }
public void validateInfo()
***************
*** 675,679 ****
private Vector<AgentIndex> agent_list;
! Directory(){agent_list = new Vector<AgentIndex>();}
public int size(){return agent_list.size();}
--- 732,756 ----
private Vector<AgentIndex> agent_list;
! Directory(){
! agent_list = new Vector<AgentIndex>();
!
! // This timer looks for and removes expired clusters.
! // Added by Liang Fok.
! new Timer().scheduleAtFixedRate(new TimerTask(){
! public void run(){
! Vector<Integer> expiredClusters = getExpiredClusters();
! print("***" + expiredClusters.size() + " EXPIRED CLUSTERS***");
! for (int i = 0; i < expiredClusters.size(); i++) {
! try {
! int ch_id = expiredClusters.get(i).intValue();
! print("Cluster " + ch_id + " expired, removing it from the directory");
! deleteCluster(ch_id);
! } catch(IllegalAccessException e) {
! e.printStackTrace();
! }
! }
! }
! }, 0, CH_UPDATE_INTERVAL* 1000);
! }
public int size(){return agent_list.size();}
More information about the Tinyos-contrib-commits
mailing list