protected void doSubscribe(final URL url, final NotifyListener listener) {
try {
if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
String root = toRootPath();
IZkChildListener zkListener = zkListeners.get(listener);
if (zkListener == null) {
zkListeners.putIfAbsent(listener, new IZkChildListener() {
public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
for (String child : currentChilds) {
if (! anyServices.contains(child)) {
anyServices.add(child);
subscribe(url.setPath(child).addParameters(Constants.INTERFACE_KEY, child,
Constants.CHECK_KEY, String.valueOf(false), Constants.REGISTER_KEY, String.valueOf(false)), listener);
}
}
}
});
zkListener = zkListeners.get(listener);
}
List<String> services = zkClient.subscribeChildChanges(root, zkListener);
if (services != null && services.size() > 0) {
anyServices.addAll(services);
for (String service : services) {
subscribe(url.setPath(service).addParameters(Constants.INTERFACE_KEY, service,
Constants.CHECK_KEY, String.valueOf(false), Constants.REGISTER_KEY, String.valueOf(false)), listener);
}
}
} else {
List<String> providers = new ArrayList<String>();
for (String path : toCategoriesPath(url)) {
IZkChildListener zkListener = zkListeners.get(listener);
if (zkListener == null) {
zkListeners.putIfAbsent(listener, new IZkChildListener() {
public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
ZookeeperRegistry.this.notify(url, listener, toUrls(url, currentChilds));
}
});
zkListener = zkListeners.get(listener);