From: Olivier Lamy Date: Wed, 2 Nov 2011 23:19:46 +0000 (+0000) Subject: correctly close index on shutdown X-Git-Tag: archiva-1.4-M2~176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=545a16dbc848387c162fee64f73bbe3c0e820ee5;p=archiva.git correctly close index on shutdown git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1196856 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index f1ad9c598..9bb5cfd2d 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -55,6 +55,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Named; import java.io.File; @@ -104,10 +105,24 @@ public class DefaultManagedRepositoryAdmin @Inject protected RoleManager roleManager; + // fields + List indexCreators; + + NexusIndexer indexer; + @PostConstruct private void initialize() throws RepositoryAdminException { + try + { + indexCreators = mavenIndexerUtils.getAllIndexCreators(); + indexer = plexusSisuBridge.lookup( NexusIndexer.class ); + } + catch ( PlexusSisuBridgeException e ) + { + throw new RepositoryAdminException( e.getMessage(), e ); + } // initialize index context on start for ( ManagedRepository managedRepository : getManagedRepositories() ) { @@ -115,6 +130,28 @@ public class DefaultManagedRepositoryAdmin } } + @PreDestroy + private void shutdown() + throws RepositoryAdminException + { + try + { + // close index on shutdown + for ( ManagedRepository managedRepository : getManagedRepositories() ) + { + IndexingContext context = indexer.getIndexingContexts().get( managedRepository.getId() ); + if ( context != null ) + { + indexer.removeIndexingContext( context, false ); + } + } + } + catch ( IOException e ) + { + throw new RepositoryAdminException( e.getMessage(), e ); + } + } + public List getManagedRepositories() throws RepositoryAdminException { @@ -523,8 +560,6 @@ public class DefaultManagedRepositoryAdmin { try { - List indexCreators = mavenIndexerUtils.getAllIndexCreators(); - NexusIndexer indexer = plexusSisuBridge.lookup( NexusIndexer.class ); IndexingContext context = indexer.getIndexingContexts().get( repository.getId() ); @@ -567,10 +602,6 @@ public class DefaultManagedRepositoryAdmin { throw new RepositoryAdminException( e.getMessage(), e ); } - catch ( PlexusSisuBridgeException e ) - { - throw new RepositoryAdminException( e.getMessage(), e ); - } catch ( UnsupportedExistingLuceneIndexException e ) { throw new RepositoryAdminException( e.getMessage(), e ); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java index 4c703c5cc..17871f098 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/remote/DefaultRemoteRepositoryAdmin.java @@ -38,6 +38,7 @@ import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import javax.inject.Inject; import java.io.File; import java.io.IOException; @@ -63,16 +64,52 @@ public class DefaultRemoteRepositoryAdmin @Inject private MavenIndexerUtils mavenIndexerUtils; + // fields + List indexCreators; + + NexusIndexer indexer; + @PostConstruct private void initialize() throws RepositoryAdminException { + try + { + indexCreators = mavenIndexerUtils.getAllIndexCreators(); + indexer = plexusSisuBridge.lookup( NexusIndexer.class ); + } + catch ( PlexusSisuBridgeException e ) + { + throw new RepositoryAdminException( e.getMessage(), e ); + } for ( RemoteRepository remoteRepository : getRemoteRepositories() ) { createIndexContext( remoteRepository ); } } + @PreDestroy + private void shutdown() + throws RepositoryAdminException + { + try + { + // close index on shutdown + for ( RemoteRepository remoteRepository : getRemoteRepositories() ) + { + IndexingContext context = indexer.getIndexingContexts().get( remoteRepository.getId() ); + if ( context != null ) + { + indexer.removeIndexingContext( context, false ); + } + } + } + catch ( IOException e ) + { + throw new RepositoryAdminException( e.getMessage(), e ); + } + } + public List getRemoteRepositories() throws RepositoryAdminException @@ -220,11 +257,8 @@ public class DefaultRemoteRepositoryAdmin // FIXME get this from ArchivaAdministration String appServerBase = System.getProperty( "appserver.base" ); - List indexCreators = mavenIndexerUtils.getAllIndexCreators(); - NexusIndexer nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); - String contextKey = "remote-" + remoteRepository.getId(); - IndexingContext indexingContext = nexusIndexer.getIndexingContexts().get( contextKey ); + IndexingContext indexingContext = indexer.getIndexingContexts().get( contextKey ); if ( indexingContext != null ) { return indexingContext; @@ -240,10 +274,9 @@ public class DefaultRemoteRepositoryAdmin { indexDirectory.mkdirs(); } - return nexusIndexer.addIndexingContext( contextKey, remoteRepository.getId(), repoDir, indexDirectory, - remoteRepository.getUrl(), - calculateIndexRemoteUrl( remoteRepository ), - mavenIndexerUtils.getAllIndexCreators() ); + return indexer.addIndexingContext( contextKey, remoteRepository.getId(), repoDir, indexDirectory, + remoteRepository.getUrl(), calculateIndexRemoteUrl( remoteRepository ), + mavenIndexerUtils.getAllIndexCreators() ); } catch ( MalformedURLException e ) { @@ -253,10 +286,6 @@ public class DefaultRemoteRepositoryAdmin { throw new RepositoryAdminException( e.getMessage(), e ); } - catch ( PlexusSisuBridgeException e ) - { - throw new RepositoryAdminException( e.getMessage(), e ); - } catch ( UnsupportedExistingLuceneIndexException e ) { throw new RepositoryAdminException( e.getMessage(), e );