// Build up the names of the added and removed workspace names ...
Set<String> addedWorkspaces = new HashSet<>();
Set<String> removedWorkspaces = new HashSet<>();
for (Change change : changeSet) {
if (change instanceof WorkspaceAdded) {
WorkspaceAdded added = (WorkspaceAdded)change;
addedWorkspaces.add(added.getWorkspaceName());
} else if (change instanceof WorkspaceRemoved) {
WorkspaceRemoved removed = (WorkspaceRemoved)change;
removedWorkspaces.add(removed.getWorkspaceName());
}
}
if (!addedWorkspaces.isEmpty() || !removedWorkspaces.isEmpty()) {
// Figure out which providers need to be called, and which definitions go with those providers ...
Map<String, List<IndexDefinition>> defnsByProvider = new HashMap<>();
for (IndexDefinition defn : indexes.getIndexDefinitions().values()) {
String providerName = defn.getProviderName();
List<IndexDefinition> defns = defnsByProvider.get(providerName);
if (defns == null) {
defns = new ArrayList<>();
defnsByProvider.put(providerName, defns);
}
defns.add(defn);
}
// Then for each provider ...
for (Map.Entry<String, List<IndexDefinition>> entry : defnsByProvider.entrySet()) {
String providerName = entry.getKey();
WorkspaceIndexChanges changes = new WorkspaceIndexChanges(entry.getValue(), addedWorkspaces,
removedWorkspaces);
IndexProvider provider = providers.get(providerName);
if (provider == null) continue;
provider.notify(changes, repository.changeBus(), repository.nodeTypeManager(),
repository.repositoryCache().getWorkspaceNames(), feedback.forProvider(providerName));
}
}
}
return feedback;
}
if (!systemWorkspaceName.equals(changeSet.getWorkspaceName())) {
// The change does not affect the 'system' workspace, so skip it ...
return null;
}
// It is simple to listen to all local and remote changes. Therefore, any changes made locally to the index definitions
// will be propagated through the cached representation via this listener.
AtomicReference<Map<Name, IndexChangeInfo>> changesByProviderName = new AtomicReference<>();
for (Change change : changeSet) {
if (change instanceof NodeAdded) {
NodeAdded added = (NodeAdded)change;
Path addedPath = added.getPath();
if (indexesPath.isAncestorOf(addedPath)) {
// Get the name of the affected provider ...
Name providerName = addedPath.getSegment(2).getName();
if (addedPath.size() > 3) {
// Adding an index (or column definition), but all we care about is the name of the index