aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaria Odea B. Ching <oching@apache.org>2008-08-14 07:02:04 +0000
committerMaria Odea B. Ching <oching@apache.org>2008-08-14 07:02:04 +0000
commitbdbb5faf461724f8c97b1aff6b301aac0539bede (patch)
treea76968ab8cac66820c6afe11cc88f9833d2c76cd
parentc43c6b90a6ae58ee7d8bba16b5ca07ed580bd78d (diff)
downloadarchiva-bdbb5faf461724f8c97b1aff6b301aac0539bede.tar.gz
archiva-bdbb5faf461724f8c97b1aff6b301aac0539bede.zip
[MRM-848]
submitted by Gwen Harold Autencio -queue scanning of repositories during startup -scan only the repositories which haven't been scanned previously by checking the scan statistics additional changes made to patch: -applied codestyle formatting -cleared the queuedRepos list when task scheduler is stopped git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@685789 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
index 57339926c..6af0ce2dc 100644
--- a/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
+++ b/archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
@@ -25,6 +25,9 @@ import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.ConfigurationEvent;
import org.apache.maven.archiva.configuration.ConfigurationListener;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.database.ArchivaDAO;
+import org.apache.maven.archiva.database.constraints.MostRecentRepositoryScanStatistics;
+import org.apache.maven.archiva.repository.scanner.RepositoryScanStatistics;
import org.apache.maven.archiva.scheduled.tasks.ArchivaTask;
import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
import org.apache.maven.archiva.scheduled.tasks.RepositoryTask;
@@ -46,6 +49,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.ParseException;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -81,6 +85,11 @@ public class DefaultArchivaTaskScheduler
* @plexus.requirement
*/
private ArchivaConfiguration archivaConfiguration;
+
+ /**
+ * @plexus.requirement role-hint="jdo"
+ */
+ private ArchivaDAO dao;
public static final String DATABASE_SCAN_GROUP = "database-group";
@@ -97,6 +106,8 @@ public class DefaultArchivaTaskScheduler
public static final String CRON_HOURLY = "0 0 * * * ?";
private Set<String> jobs = new HashSet<String>();
+
+ private List<String> queuedRepos = new ArrayList<String>();
public void startup()
throws ArchivaException
@@ -126,6 +137,11 @@ public class DefaultArchivaTaskScheduler
if ( repoConfig.isScanned() )
{
scheduleRepositoryJobs( repoConfig );
+
+ if( !isPreviouslyScanned( repoConfig ) )
+ {
+ queueInitialRepoScan( repoConfig );
+ }
}
}
@@ -137,6 +153,54 @@ public class DefaultArchivaTaskScheduler
}
}
+ private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig )
+ {
+ List<RepositoryScanStatistics> results =
+ dao.query( new MostRecentRepositoryScanStatistics( repoConfig.getId() ) );
+
+ if ( results != null && !results.isEmpty() )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ // MRM-848: Pre-configured repository initially appear to be empty
+ private synchronized void queueInitialRepoScan( ManagedRepositoryConfiguration repoConfig )
+ {
+ String repoId = repoConfig.getId();
+
+ RepositoryTask task = new RepositoryTask();
+ task.setRepositoryId( repoId );
+ task.setName( REPOSITORY_JOB + ":" + repoId + ":initial-scan" );
+ task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
+
+ boolean scheduleTask = false;
+
+ if ( queuedRepos.contains( repoId ) )
+ {
+ log.error( "Repository [" + repoId + "] is currently being processed or is already queued." );
+ }
+ else
+ {
+ scheduleTask = true;
+ }
+
+ if ( scheduleTask )
+ {
+ try
+ {
+ queuedRepos.add( repoConfig.getId() );
+ this.queueRepositoryTask( task );
+ }
+ catch ( TaskQueueException e )
+ {
+ log.error( "Error occurred while queueing repository [" + repoId + "] task : " + e.getMessage() );
+ }
+ }
+ }
+
private synchronized void scheduleRepositoryJobs( ManagedRepositoryConfiguration repoConfig )
throws SchedulerException
{
@@ -230,6 +294,7 @@ public class DefaultArchivaTaskScheduler
scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP );
}
jobs.clear();
+ queuedRepos.clear();
}
catch ( SchedulerException e )
{