prevent running in parrallel

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1551476 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2013-12-17 07:29:40 +00:00
parent 1e1f7cdacd
commit d5830c882e
1 changed files with 22 additions and 6 deletions

View File

@ -65,6 +65,8 @@ public class DefaultIndexMerger
private List<TemporaryGroupIndex> temporaryGroupIndexes = new CopyOnWriteArrayList<TemporaryGroupIndex>(); private List<TemporaryGroupIndex> temporaryGroupIndexes = new CopyOnWriteArrayList<TemporaryGroupIndex>();
private List<String> runningGroups = new CopyOnWriteArrayList<String>();
@Inject @Inject
public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils ) public DefaultIndexMerger( PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
@ -77,19 +79,29 @@ public class DefaultIndexMerger
public IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest ) public IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest )
throws IndexMergerException throws IndexMergerException
{ {
String groupId = indexMergerRequest.getGroupId();
if ( runningGroups.contains( groupId ) )
{
log.info( "skip build merge remote indexes for id: '{}' as already running", groupId );
return null;
}
runningGroups.add( groupId );
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
stopWatch.reset(); stopWatch.reset();
stopWatch.start(); stopWatch.start();
File tempRepoFile = indexMergerRequest.getMergedIndexDirectory(); File mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory();
String tempRepoId = tempRepoFile.getName(); String tempRepoId = mergedIndexDirectory.getName();
try try
{ {
File indexLocation = new File( tempRepoFile, indexMergerRequest.getMergedIndexPath() ); File indexLocation = new File( mergedIndexDirectory, indexMergerRequest.getMergedIndexPath() );
IndexingContext indexingContext = IndexingContext indexingContext =
indexer.addIndexingContext( tempRepoId, tempRepoId, tempRepoFile, indexLocation, null, null, indexer.addIndexingContext( tempRepoId, tempRepoId, mergedIndexDirectory, indexLocation, null, null,
mavenIndexerUtils.getAllIndexCreators() ); mavenIndexerUtils.getAllIndexCreators() );
for ( String repoId : indexMergerRequest.getRepositoriesIds() ) for ( String repoId : indexMergerRequest.getRepositoriesIds() )
@ -108,8 +120,8 @@ public class DefaultIndexMerger
IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexLocation ); IndexPackingRequest request = new IndexPackingRequest( indexingContext, indexLocation );
indexPacker.packIndex( request ); indexPacker.packIndex( request );
} }
temporaryGroupIndexes.add( temporaryGroupIndexes.add( new TemporaryGroupIndex( mergedIndexDirectory, tempRepoId, groupId,
new TemporaryGroupIndex( tempRepoFile, tempRepoId, indexMergerRequest.getGroupId(), indexMergerRequest.getMergedIndexTtl() ) ); indexMergerRequest.getMergedIndexTtl() ) );
stopWatch.stop(); stopWatch.stop();
log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(),
stopWatch.getTime() ); stopWatch.getTime() );
@ -123,6 +135,10 @@ public class DefaultIndexMerger
{ {
throw new IndexMergerException( e.getMessage(), e ); throw new IndexMergerException( e.getMessage(), e );
} }
finally
{
runningGroups.remove( groupId );
}
} }
@Async @Async