/**
* Reindex the repository only if there is at least one provider that required scanning and reindexing.
*/
protected void reindexIfNeeded() {
final ScanningRequest request = toBeScanned.drain();
if (!request.isEmpty()) {
final IndexWriter writer = indexManager.getIndexWriterForProviders(request.providerNames());
final RepositoryCache repoCache = runningState.repositoryCache();
scan(true, writer, new Callable<Void>() {
@Override
public Void call() throws Exception {
// Scan each of the workspace-path pairs ...
ScanOperation op = new ScanOperation() {
@Override
public void scan( String workspaceName,
Path path ) {
NodeCache workspaceCache = repoCache.getWorkspaceCache(workspaceName);
if (workspaceCache != null) {
// The workspace is still valid ...
CachedNode node = workspaceCache.getNode(workspaceCache.getRootKey());
if (!path.isRoot()) {
for (Path.Segment segment : path) {
ChildReference child = node.getChildReferences(workspaceCache).getChild(segment);
if (child == null) {
// The child no longer exists, so ignore this pair ...
node = null;
break;
}
node = workspaceCache.getNode(child);
if (node == null) break;
}
}
if (node != null) {
// If we find a node to start at, then scan the content ...
boolean scanSystemContent = repoCache.getSystemWorkspaceName().equals(workspaceName);
reindexContent(workspaceName, workspaceCache, node, Integer.MAX_VALUE, scanSystemContent,
writer);
}
}
}
};
request.onEachPathInWorkspace(op);
return null;
}
});
}
}