}
public void updateRepositoryIndexContext(final String repositoryId)
throws IOException, NoSuchRepositoryException
{
final Repository repository = repositoryRegistry.getRepository(repositoryId);
// cannot do "!repository.isIndexable()" since we may be called to handle that config change (using events)!
// the repo might be already non-indexable, but the context would still exist!
if (!SUPPORTED(repository)) {
return;
}
// the point of this if-else is to trigger NoSuchRepositoryException
if (repository.getRepositoryKind().isFacetAvailable(GroupRepository.class)) {
// group repository
repositoryRegistry.getRepositoryWithFacet(repositoryId, GroupRepository.class);
}
else {
repositoryRegistry.getRepositoryWithFacet(repositoryId, Repository.class);
}
exclusiveSingle(repository, new Runnable()
{
@Override
public void run(IndexingContext context)
throws IOException
{
log.debug("Updating indexing context for repository {}", repository.getId());
File repoRoot = getRepositoryLocalStorageAsFile(repository);
// remove context, if it already existed (ctx != null) and any of the following is true:
// is a group OR repo path changed OR we have an isIndexed transition happening
if (context != null
&& (ISGROUP(repository) || !INDEXABLE(repository)
|| !context.getRepository().getAbsolutePath().equals(repoRoot.getAbsolutePath()) ||
context.isSearchable() != repository.isSearchable())) {
// remove the context
removeRepositoryIndexContext(repository, false);
context = null;
}
// add context, if it did not existed yet (ctx == null) or any of the following is true:
// is a group OR repo path changed OR we have an isIndexed transition happening
if (INDEXABLE(repository) && context == null) {
// recreate the context
try {
addRepositoryIndexContext(repository);
}
catch (NoSuchRepositoryException e) {
// this can only happen if the repository was removed or changed type by another thread
log.debug("Could not add indexing context for repository {}", repositoryId, e);
}
}
log.debug("Updated indexing context for repository {}", repository.getId());
}
});
}