Set<String> oldSet = _tablesPerCluster.put(cluster, newSet);
Set<String> newTables = getNewTables(newSet, oldSet);
for (String table : newTables) {
final String clusterTableKey = getClusterTableKey(cluster, table);
WatchNodeExistance readOnlyWatcher = new WatchNodeExistance(_zk, ZookeeperPathConstants.getTableReadOnlyPath(
cluster, table));
readOnlyWatcher.watch(new WatchNodeExistance.OnChange() {
@Override
public void action(Stat stat) {
if (stat == null) {
_readOnly.put(clusterTableKey, Boolean.FALSE);
} else {
_readOnly.put(clusterTableKey, Boolean.TRUE);
}
}
});
if (_readOnlyWatchNodeExistance.putIfAbsent(clusterTableKey, readOnlyWatcher) != null) {
readOnlyWatcher.close();
}
WatchNodeExistance enabledWatcher = new WatchNodeExistance(_zk, ZookeeperPathConstants.getTableEnabledPath(
cluster, table));
enabledWatcher.watch(new WatchNodeExistance.OnChange() {
@Override
public void action(Stat stat) {
if (stat == null) {
_enabled.put(clusterTableKey, Boolean.FALSE);
} else {
_enabled.put(clusterTableKey, Boolean.TRUE);
}
}
});
if (_enabledWatchNodeExistance.putIfAbsent(clusterTableKey, enabledWatcher) != null) {
enabledWatcher.close();
}
}
}