Example #1
0
 public NodeDescriptor getSingleSubscribedBroker(Filter filter) {
   NodeDescriptor foundBroker = null;
   // iterates over the subscribed neighbors
   Set keys = data.keySet();
   synchronized (data) {
     Iterator it = keys.iterator();
     while (it.hasNext()) {
       NodeDescriptor currentNeighbor = (NodeDescriptor) it.next();
       if (((Collection) data.get(currentNeighbor)).contains(filter)) {
         if (foundBroker != null || !currentNeighbor.isBroker()) { // more
           // than
           // one
           // broker
           // found
           // or
           // a
           // client
           // found
           return null;
         }
         foundBroker = currentNeighbor;
       }
     }
   }
   return foundBroker;
 }
Example #2
0
 public Collection getAllFiltersExcept(boolean duplicate, NodeDescriptor n) {
   Collection result = new ArrayList();
   Set keys = data.keySet();
   synchronized (data) {
     Iterator it = keys.iterator();
     NodeDescriptor currentNeighbor;
     while (it.hasNext()) {
       currentNeighbor = (NodeDescriptor) it.next();
       if (currentNeighbor.equals(n)) continue; // skip neighbor n
       Collection filters = (Collection) data.get(currentNeighbor);
       if (duplicate) result.addAll(filters);
       else {
         Iterator it1 = filters.iterator();
         while (it1.hasNext()) {
           Filter f = (Filter) it1.next();
           if (!result.contains(f)) result.add(f);
         }
       }
     }
   }
   return result;
 }
Example #3
0
 public Collection matches(Message message, NodeDescriptor senderID) {
   List matchingNeighbors = new ArrayList();
   // iterates over the subscribed neighbors
   Set keys = data.keySet();
   synchronized (data) {
     Iterator it = keys.iterator();
     NodeDescriptor currentNeighbor;
     while (it.hasNext()) {
       currentNeighbor = (NodeDescriptor) it.next();
       // Check if currentNeighbor is subscribed to the message
       // iterates over the set of filters for currentNeighbor
       if (senderID.equals(currentNeighbor)) continue;
       Iterator it1 = ((Collection) data.get(currentNeighbor)).iterator();
       while (it1.hasNext()) {
         Filter f = (Filter) it1.next();
         if (f.matches(message)) {
           matchingNeighbors.add(currentNeighbor);
           break;
         }
       }
     }
   }
   return matchingNeighbors;
 }