From 8e169a278292e03865f5b3aca7eedacc8972755f Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 29 May 2011 21:29:40 +0000 Subject: [PATCH] updated Quartz scheduling package to support Quartz 1.8 as well --- .../quartz/LocalTaskExecutorThreadPool.java | 9 ++++++- .../scheduling/quartz/SchedulerAccessor.java | 26 +++++++++++++++---- .../quartz/SchedulerFactoryBean.java | 8 +++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java index 54f25a4d62..8738e21a51 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java +++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,13 @@ public class LocalTaskExecutorThreadPool implements ThreadPool { private Executor taskExecutor; + public void setInstanceId(String schedInstId) { + } + + public void setInstanceName(String schedName) { + } + + public void initialize() throws SchedulerConfigException { // Absolutely needs thread-bound TaskExecutor to initialize. this.taskExecutor = SchedulerFactoryBean.getConfigTimeTaskExecutor(); diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java index e3473520fc..88aa050731 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java +++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.scheduling.quartz; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; @@ -34,7 +35,6 @@ import org.quartz.SchedulerListener; import org.quartz.Trigger; import org.quartz.TriggerListener; import org.quartz.spi.ClassLoadHelper; -import org.quartz.xml.JobSchedulingDataProcessor; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; @@ -240,9 +240,25 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { if (this.jobSchedulingDataLocations != null) { ClassLoadHelper clh = new ResourceLoaderClassLoadHelper(this.resourceLoader); clh.initialize(); - JobSchedulingDataProcessor dataProcessor = new JobSchedulingDataProcessor(clh, true, true); - for (String location : this.jobSchedulingDataLocations) { - dataProcessor.processFileAndScheduleJobs(location, getScheduler(), this.overwriteExistingJobs); + try { + // Quartz 1.8 or higher? + Class dataProcessorClass = getClass().getClassLoader().loadClass("import org.quartz.xml.XMLSchedulingDataProcessor"); + logger.debug("Using Quartz 1.8 XMLSchedulingDataProcessor"); + Object dataProcessor = dataProcessorClass.getConstructor(ClassLoadHelper.class).newInstance(clh); + Method processFileAndScheduleJobs = dataProcessorClass.getMethod("processFileAndScheduleJobs", String.class, Scheduler.class); + for (String location : this.jobSchedulingDataLocations) { + processFileAndScheduleJobs.invoke(dataProcessor, location, getScheduler()); + } + } + catch (ClassNotFoundException ex) { + // Quartz 1.6 + Class dataProcessorClass = getClass().getClassLoader().loadClass("import org.quartz.xml.JobSchedulingDataProcessor"); + logger.debug("Using Quartz 1.6 JobSchedulingDataProcessor"); + Object dataProcessor = dataProcessorClass.getConstructor(ClassLoadHelper.class, boolean.class, boolean.class).newInstance(clh, true, true); + Method processFileAndScheduleJobs = dataProcessorClass.getMethod("processFileAndScheduleJobs", String.class, Scheduler.class, boolean.class); + for (String location : this.jobSchedulingDataLocations) { + processFileAndScheduleJobs.invoke(dataProcessor, location, getScheduler(), this.overwriteExistingJobs); + } } } diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java index 24c42e341c..2abaab665d 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java +++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,9 +74,9 @@ import org.springframework.util.CollectionUtils; * automatically apply to Scheduler operations performed within those scopes. * Alternatively, you may add transactional advice for the Scheduler itself. * - *

Note: This version of Spring's SchedulerFactoryBean requires - * Quartz 1.5.x or 1.6.x. The "jobSchedulingDataLocation" feature requires - * Quartz 1.6.1 or higher (as of Spring 2.5.5). + *

Note: This version of Spring's SchedulerFactoryBean supports Quartz 1.x, + * more specifically Quartz 1.5 or higher. The "jobSchedulingDataLocation" feature + * requires Quartz 1.6.1 or higher (as of Spring 2.5.5). * * @author Juergen Hoeller * @since 18.02.2004