Exemplo n.º 1
0
 // ------------------------------------------------------
 // for "AttrRqst"
 // Return: attrbute list for the URL/"service type"
 //         format: (attr1=value1),(attr2=value2)
 // if tag != "", return ONLY those attributes in tag
 // ------------------------------------------------------
 public synchronized String getAttrList(String url, String scope, String tag, String ltag) {
   if (table.containsKey(ltag + url)) {
     Entry e = (Entry) table.get(ltag + url);
     if (!e.getDeleted() && scope.equalsIgnoreCase(e.getScope())) {
       return e.getAttr(tag);
     } else {
       return "";
     }
   } else { // Not URL, try servive type
     return typeAttrList(url, scope, tag, ltag);
   }
 }
Exemplo n.º 2
0
 private synchronized String typeAttrList(String type, String scope, String tag, String ltag) {
   StringBuffer attrList = new StringBuffer();
   Iterator values = table.values().iterator();
   while (values.hasNext()) {
     Entry e = (Entry) values.next();
     if (!e.getDeleted()
         && type.equalsIgnoreCase(e.getType())
         && scope.equalsIgnoreCase(e.getScope())
         && ltag.equalsIgnoreCase(e.getLtag())) {
       String s = e.getAttr(tag);
       if (attrList.length() > 0) attrList.append(",");
       attrList.append(s);
     }
   }
   return attrList.toString();
 }
Exemplo n.º 3
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);
     }
   }
 }