Пример #1
0
 // -------------------------------------------
 // check lifetime and remove expired entries
 // -------------------------------------------
 public synchronized void rmExpiredEntry() {
   long currtime = System.currentTimeMillis();
   Iterator keys = table.keySet().iterator();
   while (keys.hasNext()) {
     String k = (String) keys.next();
     Entry e = (Entry) table.get(k);
     if (currtime > (e.getArrivalTS() + e.getLifetime() * 1000)) {
       keys.remove();
     }
   }
 }
Пример #2
0
 // ------------------------------------------------------------------
 // send newer updates to the peer through "tcp" peering connection
 // compare each entry's updating ID with IDs in (adalist, atslist)
 // ------------------------------------------------------------------
 public synchronized void antiEntropy(slpTcpHandler tcp, String scope, String rda, long rts) {
   TreeMap tmp = new TreeMap();
   Iterator values = table.values().iterator();
   while (values.hasNext()) {
     Entry e = (Entry) values.next();
     String ada = e.getAcceptDA();
     long ats = e.getAcceptTS();
     if (ada.equalsIgnoreCase(rda)
         && ats > rts
         && // for newer updates
         Util.shareString(scope, e.getScope(), ",")) {
       tmp.put(new Long(ats), e.getLtag().concat(e.getURL()));
     }
   }
   long ctime = System.currentTimeMillis() / 1000;
   values = tmp.values().iterator();
   while (values.hasNext()) {
     String k = (String) values.next();
     Entry e = (Entry) table.get(k);
     int ltime = (int) (e.getArrivalTS() / 1000 + e.getLifetime() - ctime);
     byte[] buf =
         composer.SrvReg(
             0,
             Const.fresh_flag,
             e.getLtag(),
             e.getURL(),
             ltime,
             e.getType(),
             e.getScope(),
             e.getAttr(""));
     buf =
         composer.MeshFwdExt(buf, Const.Fwded, e.getVersionTS(), e.getAcceptDA(), e.getAcceptTS());
     tcp.send(buf, buf.length);
     if (e.getDeleted()) {
       buf = composer.SrvDeReg(0, e.getLtag(), e.getScope(), e.getURL(), ltime, "");
       buf =
           composer.MeshFwdExt(
               buf, Const.Fwded, e.getVersionTS(), e.getAcceptDA(), e.getAcceptTS());
       tcp.send(buf, buf.length);
     }
   }
 }