]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1837] cleanup registry listeners from Archiva Configuration
authorOlivier Lamy <olamy@apache.org>
Wed, 30 Apr 2014 07:22:41 +0000 (17:22 +1000)
committerOlivier Lamy <olamy@apache.org>
Wed, 30 Apr 2014 07:22:41 +0000 (17:22 +1000)
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/ArchivaConfiguration.java
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-api/src/main/java/org/apache/archiva/consumers/KnownRepositoryContentConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/main/java/org/apache/archiva/consumers/core/MetadataUpdaterConsumer.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MockConfiguration.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/DefaultRepositoryScanner.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/RepositoryContentConsumers.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/configuration/TestConfiguration.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/conf/MockConfiguration.java
archiva-modules/plugins/stage-repository-merge/src/test/java/org/apache/archiva/configuration/StubConfiguration.java

index 3a259da85501c05954aaf8b4f0ed4f90f35af933..4f6798c10a4021060fa328c49deebf34e3a2bb80 100644 (file)
@@ -70,13 +70,15 @@ public interface ArchivaConfiguration
     void removeListener( ConfigurationListener listener );
 
     /**
-     * Add a registry listener to notify of events in plexus-registry.
+     * Add a registry listener to notify of events in spring-registry.
      *
      * @param listener the listener
      *                 TODO: Remove in future.
      */
     void addChangeListener( RegistryListener listener );
 
+    void removeChangeListener( RegistryListener listener );
+
     /**
      * reload configuration from file included registry
      *
index 6373a503b2551a3a0f5ad54fefc72d5865043339..9b403d1d24c35fb6cb844a70b015839149ee7c81 100644 (file)
@@ -650,6 +650,8 @@ public class DefaultArchivaConfiguration
         listeners.remove( listener );
     }
 
+
+
     @Override
     public void addChangeListener( RegistryListener listener )
     {
@@ -673,6 +675,13 @@ public class DefaultArchivaConfiguration
         }
     }
 
+    @Override
+    public void removeChangeListener( RegistryListener listener )
+    {
+        boolean removed = registryListeners.remove( listener );
+        log.debug( "RegistryListener: '{}' removed {}", listener, removed );
+    }
+
     @PostConstruct
     public void initialize()
     {
index e1b6009f22ad70940f1bda60ea6b622aa6ca4992..cb1f78f5cf6a78f153424e1454421ebb2208efb3 100644 (file)
@@ -70,32 +70,17 @@ public class MetadataUpdaterConsumer
      */
     private String id = "metadata-updater";
 
-    /**
-     * default-value="Update / Create maven-metadata.xml files"
-     */
     private String description = "Update / Create maven-metadata.xml files";
 
-    /**
-     *
-     */
     @Inject
     private RepositoryContentFactory repositoryFactory;
 
-    /**
-     *
-     */
     @Inject
     private MetadataTools metadataTools;
 
-    /**
-     *
-     */
     @Inject
     private ArchivaConfiguration configuration;
 
-    /**
-     *
-     */
     @Inject
     private FileTypes filetypes;
 
index 7cd49a6520b064b12ff8a158eb85f6b540f4cade..935f2a6e03cb5e0e3c67e6c234cc266c3ae42deb 100644 (file)
@@ -88,6 +88,12 @@ public class MockConfiguration
         registryListeners.add( listener );
     }
 
+    @Override
+    public void removeChangeListener( RegistryListener listener )
+    {
+        registryListeners.remove( listener );
+    }
+
     @Override
     public Configuration getConfiguration()
     {
index 492845d4f516d4c1480a9992cefbf269bfd9eec8..56ef2fd42ab7965573096c1626045e522e29487f 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.archiva.repository.scanner;
 
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.FileTypes;
 import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
@@ -32,6 +33,7 @@ import org.springframework.stereotype.Service;
 import javax.inject.Inject;
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -57,9 +59,10 @@ public class DefaultRepositoryScanner
     public RepositoryScanStatistics scan( ManagedRepository repository, long changesSince )
         throws RepositoryScannerException
     {
+        List<KnownRepositoryContentConsumer> knownContentConsumers = null;
         try
         {
-            List<KnownRepositoryContentConsumer> knownContentConsumers = repositoryContentConsumers.getSelectedKnownConsumers();
+            knownContentConsumers = repositoryContentConsumers.getSelectedKnownConsumers();
             List<InvalidRepositoryContentConsumer> invalidContentConsumers = repositoryContentConsumers.getSelectedInvalidConsumers();
             List<String> ignoredPatterns = filetypes.getFileTypePatterns( FileTypes.IGNORED );
 
@@ -68,6 +71,9 @@ public class DefaultRepositoryScanner
         catch ( RepositoryAdminException e )
         {
             throw new RepositoryScannerException( e.getMessage(), e );
+        } finally
+        {
+            repositoryContentConsumers.releaseSelectedKnownConsumers( knownContentConsumers );
         }
     }
 
index 4ce22d2c485bc7c8e88386dc9ba53b8f80f069c5..4c6077a69ede181cd61d89196c37288d558e0b45 100644 (file)
@@ -23,9 +23,11 @@ import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.admin.ArchivaAdministration;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.common.utils.BaseFile;
+import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
 import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
+import org.apache.archiva.redback.components.registry.RegistryListener;
 import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
 import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure;
 import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
@@ -48,7 +50,7 @@ import java.util.Map;
 /**
  * RepositoryContentConsumerUtil
  */
-@Service( "repositoryContentConsumers" )
+@Service("repositoryContentConsumers")
 public class RepositoryContentConsumers
     implements ApplicationContextAware
 {
@@ -62,6 +64,9 @@ public class RepositoryContentConsumers
 
     private List<InvalidRepositoryContentConsumer> selectedInvalidConsumers;
 
+    @Inject
+    private ArchivaConfiguration archivaConfiguration;
+
     @Inject
     public RepositoryContentConsumers( ArchivaAdministration archivaAdministration )
     {
@@ -156,7 +161,7 @@ public class RepositoryContentConsumers
      * @return the list of {@link KnownRepositoryContentConsumer} that have been selected
      * by the active configuration.
      */
-    public synchronized List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
+    public List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
         throws RepositoryAdminException
     {
         // FIXME only for testing
@@ -178,6 +183,22 @@ public class RepositoryContentConsumers
         return ret;
     }
 
+    public void releaseSelectedKnownConsumers( List<KnownRepositoryContentConsumer> repositoryContentConsumers )
+    {
+        if ( repositoryContentConsumers == null )
+        {
+            return;
+        }
+        for ( KnownRepositoryContentConsumer knownRepositoryContentConsumer : repositoryContentConsumers )
+        {
+            if ( RegistryListener.class.isAssignableFrom( knownRepositoryContentConsumer.getClass() ) )
+            {
+                archivaConfiguration.removeChangeListener(
+                    RegistryListener.class.cast( knownRepositoryContentConsumer ) );
+            }
+        }
+    }
+
     /**
      * Get the list of {@link InvalidRepositoryContentConsumer} objects that are
      * selected according to the active configuration.
@@ -248,12 +269,13 @@ public class RepositoryContentConsumers
     public void executeConsumers( ManagedRepository repository, File localFile, boolean updateRelatedArtifacts )
         throws RepositoryAdminException
     {
+        List<KnownRepositoryContentConsumer> selectedKnownConsumers = null;
         // Run the repository consumers
         try
         {
             Closure triggerBeginScan = new TriggerBeginScanClosure( repository, getStartTime(), false );
 
-            List<KnownRepositoryContentConsumer> selectedKnownConsumers = getSelectedKnownConsumers();
+            selectedKnownConsumers = getSelectedKnownConsumers();
 
             // MRM-1212/MRM-1197 
             // - do not create missing/fix invalid checksums and update metadata when deploying from webdav since these are uploaded by maven
@@ -307,6 +329,7 @@ public class RepositoryContentConsumers
                         CollectionUtils.forAllDo( availableKnownConsumers, triggerCompleteScan );
                         CollectionUtils.forAllDo( availableInvalidConsumers, triggerCompleteScan );
             */
+            releaseSelectedKnownConsumers( selectedKnownConsumers );
         }
     }
 
index 12ab3b99c8ab0caa7bcef5b2685098a6c2f6f4cf..20562995cfa6dcf4250a51d5559a67e205cbf3a4 100644 (file)
@@ -66,6 +66,12 @@ public class TestConfiguration
         // no op
     }
 
+    @Override
+    public void removeChangeListener( RegistryListener listener )
+    {
+        // no op
+    }
+
     @Override
     public void reload()
     {
index 09ef4959f9e09c245e7858f1ba6d9994080cb1ba..51479bbbdac5c27a9f730f29c2c96158ea9a0e21 100644 (file)
@@ -64,6 +64,12 @@ public class MockConfiguration
         registryListeners.add( listener );
     }
 
+    @Override
+    public void removeChangeListener( RegistryListener listener )
+    {
+        registryListeners.remove( listener );
+    }
+
     @Override
     public Configuration getConfiguration()
     {
index 642e52371eb3113014468f8c3ed110c6659f7438..b4659ac34367ffdf2310c69c4f0dd372341be965 100644 (file)
@@ -66,6 +66,12 @@ public class StubConfiguration
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public void removeChangeListener( RegistryListener listener )
+    {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     public void reload()
     {