public void addSubscription(NodeDescriptor n, Filter f) { List filters = (List) data.get(n); if (filters == null) { filters = new ArrayList(); filters.add(f); data.put(n, filters); } else { if (!filters.contains(f)) filters.add(f); } }
public Collection getSubscribedNeighbors(Filter f) { 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 if (((Collection) data.get(currentNeighbor)).contains(f)) { matchingNeighbors.add(currentNeighbor); } } } return matchingNeighbors; }
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; }