[MRM-1837] cleanup registry listeners from Archiva Configuration

This commit is contained in:
Olivier Lamy 2014-04-30 17:22:41 +10:00
parent 9bb8edc5c8
commit 7808ee5faf
10 changed files with 69 additions and 22 deletions

View 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
*

View 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()
{

View File

@ -21,8 +21,6 @@ package org.apache.archiva.consumers;
/**
* Consumer for Known Repository Content.
*
*
*/
public interface KnownRepositoryContentConsumer
extends RepositoryContentConsumer

View 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;

View File

@ -88,6 +88,12 @@ public class MockConfiguration
registryListeners.add( listener );
}
@Override
public void removeChangeListener( RegistryListener listener )
{
registryListeners.remove( listener );
}
@Override
public Configuration getConfiguration()
{

View 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 );
}
}

View 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 );
}
}

View File

@ -66,6 +66,12 @@ public class TestConfiguration
// no op
}
@Override
public void removeChangeListener( RegistryListener listener )
{
// no op
}
@Override
public void reload()
{

View File

@ -64,6 +64,12 @@ public class MockConfiguration
registryListeners.add( listener );
}
@Override
public void removeChangeListener( RegistryListener listener )
{
registryListeners.remove( listener );
}
@Override
public Configuration getConfiguration()
{

View File

@ -66,6 +66,12 @@ public class StubConfiguration
throw new UnsupportedOperationException();
}
@Override
public void removeChangeListener( RegistryListener listener )
{
throw new UnsupportedOperationException();
}
@Override
public void reload()
{