Set<String> oldSet = _tablesPerCluster.put(_cluster, newSet);
Set<String> newTables = getNewTables(newSet, oldSet);
Set<String> oldTables = getOldTables(newSet, oldSet);
for (String table : oldTables) {
final String clusterTableKey = getClusterTableKey(_cluster, table);
WatchNodeData watch = _enabledWatchNodeExistance.remove(clusterTableKey);
if (watch != null) {
watch.close();
}
_tableDescriptorCache.remove(table);
}
for (String table : newTables) {
final String clusterTableKey = getClusterTableKey(_cluster, table);
WatchNodeData enabledWatcher = new WatchNodeData(_zk, ZookeeperPathConstants.getTablePath(_cluster, table));
enabledWatcher.watch(new WatchNodeData.OnChange() {
@Override
public void action(byte[] data) {
runActions();
_tableDescriptorCache.clear();
}
});
if (_enabledWatchNodeExistance.putIfAbsent(clusterTableKey, enabledWatcher) != null) {
enabledWatcher.close();
}
}
}