Exemplo n.º 1
0
 // ----------------------------------------------------------------------
 // for "SrvTypeRqst"
 // get the list of service types for specified scope & naming authority
 // ----------------------------------------------------------------------
 public synchronized String getServiceTypeList(String na, String scope) {
   Vector typelist = new Vector(5);
   Iterator values = table.values().iterator();
   while (values.hasNext()) {
     Entry e = (Entry) values.next();
     if (!e.getDeleted()
         && // nor deleted
         scope.equalsIgnoreCase(e.getScope())
         && // match scope
         (na.equals("*")
             || // NA wildcard
             na.equalsIgnoreCase(e.getNA()))
         && // match NA
         !typelist.contains(e.getType())) {
       typelist.addElement(e.getType());
     }
   }
   StringBuffer tl = new StringBuffer();
   for (int i = 0; i < typelist.size(); i++) {
     String s = (String) typelist.elementAt(i);
     if (tl.length() > 0) tl.append(",");
     tl.append(s);
   }
   return tl.toString();
 }
Exemplo n.º 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);
     }
   }
 }
Exemplo n.º 3
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.º 4
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.º 5
0
 // ---------------------------------------------------
 // for "SrvDeReg"
 // remove the entry with the key: ltag+url (tag=="")
 // or delete some attributes of this entry (tag!="")
 // ---------------------------------------------------
 public synchronized int rmEntry(
     String ltag,
     String url,
     String scope,
     String tag,
     long versionTS,
     String acceptDA,
     long acceptTS) {
   if (table.containsKey(ltag + url)) {
     Entry e = (Entry) table.get(ltag + url);
     if (!scope.equalsIgnoreCase(e.getScope())) {
       return Const.SCOPE_NOT_SUPPORTED;
     }
     e.deletion(tag, versionTS, acceptDA, acceptTS);
   }
   return Const.OK;
 }