diff options
author | Olivier Lamy <olamy@apache.org> | 2011-05-27 17:26:26 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2011-05-27 17:26:26 +0000 |
commit | 789083836c3afe55278a7382b70262e279afa623 (patch) | |
tree | 99f2c79caa234cb10f4b89c3a3af5cf793a71335 /archiva-modules/archiva-scheduler | |
parent | a9b50a0fe048b4c386ca85ad22daad307643c210 (diff) | |
download | archiva-789083836c3afe55278a7382b70262e279afa623.tar.gz archiva-789083836c3afe55278a7382b70262e279afa623.zip |
[MRM-1473] remove plexus-spring use
replace plexus-quartz with spring-quartz
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1128404 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-scheduler')
6 files changed, 69 insertions, 64 deletions
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java index dbcffead1..5a20880c5 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-api/src/main/java/org/apache/archiva/scheduler/ArchivaTaskScheduler.java @@ -24,7 +24,6 @@ import org.codehaus.plexus.taskqueue.TaskQueueException; /** * The component that takes care of scheduling in the application. - * */ public interface ArchivaTaskScheduler<T extends Task> { @@ -35,10 +34,10 @@ public interface ArchivaTaskScheduler<T extends Task> /** * Adds the task to the scanning queue. - * + * * @param task * @throws TaskQueueException */ - public void queueTask( T task ) + void queueTask( T task ) throws TaskQueueException; } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml index 34756a585..fbc1d34e3 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml @@ -16,6 +16,24 @@ <artifactId>archiva-scheduler-api</artifactId> </dependency> <dependency> + <groupId>org.codehaus.redback.components</groupId> + <artifactId>spring-quartz</artifactId> + </dependency> + <dependency> + <groupId>org.quartz-scheduler</groupId> + <artifactId>quartz</artifactId> + <exclusions> + <exclusion> + <groupId>c3p0</groupId> + <artifactId>c3p0</artifactId> + </exclusion> + <exclusion> + <groupId>javax.transaction</groupId> + <artifactId>jta</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> <groupId>org.apache.archiva</groupId> <artifactId>repository-statistics</artifactId> </dependency> @@ -33,10 +51,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-quartz</artifactId> - </dependency> - <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java index 5096ff2c2..481615a00 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/ArchivaRepositoryScanningTaskExecutor.java @@ -101,7 +101,7 @@ public class ArchivaRepositoryScanningTaskExecutor public void initialize() throws InitializationException { - log.info( "Initialized " + this.getClass().getName() ); + log.info( "Initialized {}", this.getClass().getName() ); } @SuppressWarnings( "unchecked" ) diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java index 08ed231dc..67881abfc 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java @@ -30,22 +30,22 @@ 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.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException; -import org.codehaus.plexus.scheduler.CronExpressionValidator; -import org.codehaus.plexus.scheduler.Scheduler; -import org.codehaus.plexus.taskqueue.Task; import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueueException; +import org.codehaus.redback.components.scheduler.CronExpressionValidator; +import org.codehaus.redback.components.scheduler.Scheduler; import org.quartz.CronTrigger; import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.quartz.SchedulerException; +import org.quartz.impl.JobDetailImpl; +import org.quartz.impl.triggers.CronTriggerImpl; import org.slf4j.Logger; 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.text.ParseException; @@ -56,12 +56,12 @@ import java.util.Set; /** * Default implementation of a scheduling component for archiva. - * + * <p/> * plexus.component role="org.apache.archiva.scheduler.ArchivaTaskScheduler" role-hint="repository" */ -@Service("archivaTaskScheduler#repository") +@Service( "archivaTaskScheduler#repository" ) public class RepositoryArchivaTaskScheduler - implements ArchivaTaskScheduler<RepositoryTask>, Startable, ConfigurationListener + implements ArchivaTaskScheduler<RepositoryTask>, ConfigurationListener { private Logger log = LoggerFactory.getLogger( RepositoryArchivaTaskScheduler.class ); @@ -71,10 +71,14 @@ public class RepositoryArchivaTaskScheduler @Inject private Scheduler scheduler; + @Inject + CronExpressionValidator cronValidator; + /** * plexus.requirement role-hint="repository-scanning" */ - @Inject @Named(value = "taskQueue#repository-scanning") + @Inject + @Named( value = "taskQueue#repository-scanning" ) private TaskQueue repositoryScanningQueue; /** @@ -87,12 +91,12 @@ public class RepositoryArchivaTaskScheduler * plexus.requirement */ @Inject - @Named(value = "repositoryStatisticsManager#default") + @Named( value = "repositoryStatisticsManager#default" ) private RepositoryStatisticsManager repositoryStatisticsManager; /** * TODO: could have multiple implementations - * + * <p/> * plexus.requirement */ @Inject @@ -114,24 +118,12 @@ public class RepositoryArchivaTaskScheduler private List<String> queuedRepos = new ArrayList<String>(); + @PostConstruct public void startup() throws ArchivaException { archivaConfiguration.addListener( this ); - try - { - start(); - } - catch ( StartingException e ) - { - throw new ArchivaException( e.getMessage(), e ); - } - } - - public void start() - throws StartingException - { List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration().getManagedRepositories(); @@ -149,7 +141,7 @@ public class RepositoryArchivaTaskScheduler } catch ( SchedulerException e ) { - throw new StartingException( "Unable to start scheduler: " + e.getMessage(), e ); + throw new ArchivaException( "Unable to start scheduler: " + e.getMessage(), e ); } try @@ -161,8 +153,8 @@ public class RepositoryArchivaTaskScheduler } catch ( MetadataRepositoryException e ) { - log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: " + - e.getMessage(), e ); + log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: " + + e.getMessage(), e ); } } } @@ -171,24 +163,21 @@ public class RepositoryArchivaTaskScheduler { repositorySession.close(); } + } + + @PreDestroy public void stop() - throws StoppingException + throws SchedulerException { - try + for ( String job : jobs ) { - for ( String job : jobs ) - { - scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP ); - } - jobs.clear(); - queuedRepos.clear(); - } - catch ( SchedulerException e ) - { - throw new StoppingException( "Unable to unschedule tasks", e ); + scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP ); } + jobs.clear(); + queuedRepos.clear(); + } @SuppressWarnings( "unchecked" ) @@ -252,7 +241,7 @@ public class RepositoryArchivaTaskScheduler { if ( isProcessingRepositoryTask( task ) ) { - log.debug( "Repository task '" + task + "' is already queued. Skipping task." ); + log.debug( "Repository task '{}' is already queued. Skipping task.", task ); } else { @@ -348,35 +337,32 @@ public class RepositoryArchivaTaskScheduler // get the cron string for these database scanning jobs String cronString = repoConfig.getRefreshCronExpression(); - CronExpressionValidator cronValidator = new CronExpressionValidator(); if ( !cronValidator.validate( cronString ) ) { - log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId() + - "] is invalid. Defaulting to hourly." ); + log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId() + + "] is invalid. Defaulting to hourly." ); cronString = CRON_HOURLY; } // setup the unprocessed artifact job - JobDetail repositoryJob = new JobDetail( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, - RepositoryTaskJob.class ); + JobDetailImpl repositoryJob = + new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, RepositoryTaskJob.class ); - JobDataMap dataMap = new JobDataMap(); - dataMap.put( TASK_QUEUE, repositoryScanningQueue ); - dataMap.put( TASK_REPOSITORY, repoConfig.getId() ); - repositoryJob.setJobDataMap( dataMap ); + repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue ); + repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() ); try { - CronTrigger trigger = new CronTrigger( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), - REPOSITORY_SCAN_GROUP, cronString ); + CronTriggerImpl trigger = + new CronTriggerImpl( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, cronString ); jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() ); scheduler.scheduleJob( repositoryJob, trigger ); } catch ( ParseException e ) { - log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '" + - repoConfig.getId() + "': " + e.getMessage() ); + log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '" + + repoConfig.getId() + "': " + e.getMessage() ); } } diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java index ab265a5ea..9417ff686 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java @@ -19,9 +19,9 @@ package org.apache.archiva.scheduler.repository; * under the License. */ -import org.codehaus.plexus.scheduler.AbstractJob; import org.codehaus.plexus.taskqueue.TaskQueue; import org.codehaus.plexus.taskqueue.TaskQueueException; +import org.codehaus.redback.components.scheduler.AbstractJob; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml index 84d6cda5c..2fd029c41 100755 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/resources/META-INF/spring-context.xml @@ -21,10 +21,12 @@ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" + xmlns:task="http://www.springframework.org/schema/task" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context - http://www.springframework.org/schema/context/spring-context-3.0.xsd" + http://www.springframework.org/schema/context/spring-context-3.0.xsd + http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd" default-lazy-init="true"> <context:annotation-config/> @@ -37,4 +39,8 @@ <property name="executor" ref="taskExecutor#repository-scanning"/> <property name="queue" ref="taskQueue#repository-scanning"/> </bean> + <alias name="archivaTaskScheduler#repository" alias="scheduler#repository"/> + + <task:scheduler id="scheduler" pool-size="10"/> + </beans>
\ No newline at end of file |