_clusters.set(new HashSet<String>(clusters));
for (String cluster : clusters) {
if (!_tableWatchers.containsKey(cluster)) {
String tablesPath = ZookeeperPathConstants.getTablesPath(cluster);
ZkUtils.waitUntilExists(_zk, tablesPath);
WatchChildren clusterWatcher = new WatchChildren(_zk, tablesPath).watch(new Tables(cluster));
_tableWatchers.put(cluster, clusterWatcher);
}
}
List<String> clustersToCloseAndRemove = new ArrayList<String>(clusters);
clustersToCloseAndRemove.removeAll(_tableWatchers.keySet());
for (String cluster : clustersToCloseAndRemove) {
WatchChildren watcher = _tableWatchers.remove(cluster);
if (watcher == null) {
LOG.error("Error watcher is null [" + cluster + "] ");
} else {
watcher.close();
}
}
}