Example #1
0
 // -----------------------------------------------------------
 // for "SrvRqst"
 // find the matched URLs with (type, scope, predicate, ltag)
 // return: error code (short)
 //         number of matched URLs (short)
 //         URL blocks (decided bt previous #URL)
 // -----------------------------------------------------------
 public synchronized byte[] getMatchedURL(String type, String scope, String pred, String ltag) {
   byte[] buf = null;
   int ecode = Const.OK;
   if (!Util.shareString(daf.getScope(), scope, ",")) {
     ecode = Const.SCOPE_NOT_SUPPORTED;
   }
   b.reset();
   try {
     int count = 0;
     d.writeShort(ecode); // error code
     d.writeShort(count); // URL count, place holder
     if (ecode == Const.OK) { // no error, find matched URLs
       Iterator values = table.values().iterator();
       while (values.hasNext()) {
         Entry e = (Entry) values.next();
         if (e.match(type, scope, pred, ltag)) {
           count++;
           d.writeByte(0);
           d.writeShort(e.getLifetime());
           d.writeShort(e.getURL().length());
           d.writeBytes(e.getURL());
           d.writeByte(0);
         }
       }
     }
     buf = b.toByteArray();
     if (count > 0) Util.writeInt(buf, 2, count, 2); // update count
   } catch (Exception e) {
     if (ServiceLocationManager.displayMSLPTrace) e.printStackTrace();
   }
   return buf;
 }
Example #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);
     }
   }
 }