doRegister(service);
}
}
// Find new registered services...
DiscoveryListener discoveryListener = this.discoveryListener.get();
if (discoveryListener != null) {
Set<String> activeServices = doLookup(updateInterval * 3);
// If there is error talking the the central server, then
// activeServices == null
if (activeServices != null) {
synchronized (discoveredServices) {
HashSet<String> removedServices = new HashSet<String>(discoveredServices.keySet());
removedServices.removeAll(activeServices);
HashSet<String> addedServices = new HashSet<String>(activeServices);
addedServices.removeAll(discoveredServices.keySet());
addedServices.removeAll(removedServices);
for (String service : addedServices) {
SimpleDiscoveryEvent e = new SimpleDiscoveryEvent(service);
discoveredServices.put(service, e);
discoveryListener.onServiceAdd(e);
}
for (String service : removedServices) {
SimpleDiscoveryEvent e = discoveredServices.remove(service);
if (e != null) {
e.removed.set(true);
}
discoveryListener.onServiceRemove(e);
}
}
}
}
}