Consistent support for setStartTime in CronTrigger(Factory)Bean and SimpleTrigger(Factory)Bean, and consistent declaration of varargs in scheduling.quartz package
Issue: SPR-10940
This commit is contained in:
parent
38a8ace5bb
commit
b228a06e07
|
@ -73,7 +73,7 @@ public class CronTriggerBean extends CronTrigger
|
|||
|
||||
private String beanName;
|
||||
|
||||
private long startDelay;
|
||||
private long startDelay = 0;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -108,9 +108,9 @@ public class CronTriggerBean extends CronTrigger
|
|||
* @see SchedulerFactoryBean#setTriggerListeners
|
||||
* @see org.quartz.TriggerListener#getName
|
||||
*/
|
||||
public void setTriggerListenerNames(String[] names) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
addTriggerListener(names[i]);
|
||||
public void setTriggerListenerNames(String... names) {
|
||||
for (String name : names) {
|
||||
addTriggerListener(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,19 +151,15 @@ public class CronTriggerBean extends CronTrigger
|
|||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.startDelay > 0) {
|
||||
setStartTime(new Date(System.currentTimeMillis() + this.startDelay));
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() {
|
||||
if (getName() == null) {
|
||||
setName(this.beanName);
|
||||
}
|
||||
if (getGroup() == null) {
|
||||
setGroup(Scheduler.DEFAULT_GROUP);
|
||||
}
|
||||
if (getStartTime() == null) {
|
||||
setStartTime(new Date());
|
||||
if (this.startDelay > 0 || getStartTime() == null) {
|
||||
setStartTime(new Date(System.currentTimeMillis() + this.startDelay));
|
||||
}
|
||||
if (getTimeZone() == null) {
|
||||
setTimeZone(TimeZone.getDefault());
|
||||
|
|
|
@ -78,7 +78,7 @@ public class CronTriggerFactoryBean implements FactoryBean<CronTrigger>, BeanNam
|
|||
|
||||
private Date startTime;
|
||||
|
||||
private long startDelay;
|
||||
private long startDelay = 0;
|
||||
|
||||
private String cronExpression;
|
||||
|
||||
|
@ -141,6 +141,15 @@ public class CronTriggerFactoryBean implements FactoryBean<CronTrigger>, BeanNam
|
|||
this.jobDataMap.putAll(jobDataAsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a specific start time for the trigger.
|
||||
* <p>Note that a dynamically computed {@link #setStartDelay} specification
|
||||
* overrides a static timestamp set here.
|
||||
*/
|
||||
public void setStartTime(Date startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the start delay in milliseconds.
|
||||
* <p>The start delay is added to the current system time (when the bean starts)
|
||||
|
@ -208,12 +217,9 @@ public class CronTriggerFactoryBean implements FactoryBean<CronTrigger>, BeanNam
|
|||
if (this.jobDetail != null) {
|
||||
this.jobDataMap.put(JobDetailAwareTrigger.JOB_DETAIL_KEY, this.jobDetail);
|
||||
}
|
||||
if (this.startDelay > 0) {
|
||||
if (this.startDelay > 0 || this.startTime == null) {
|
||||
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
|
||||
}
|
||||
else if (this.startTime == null) {
|
||||
this.startTime = new Date();
|
||||
}
|
||||
if (this.timeZone == null) {
|
||||
this.timeZone = TimeZone.getDefault();
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Map;
|
|||
import org.quartz.Job;
|
||||
import org.quartz.JobDetail;
|
||||
import org.quartz.Scheduler;
|
||||
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
@ -47,7 +48,7 @@ import org.springframework.context.ApplicationContextAware;
|
|||
* @see org.springframework.beans.factory.BeanNameAware
|
||||
* @see org.quartz.Scheduler#DEFAULT_GROUP
|
||||
*/
|
||||
@SuppressWarnings({ "serial", "rawtypes" })
|
||||
@SuppressWarnings({"serial", "rawtypes"})
|
||||
public class JobDetailBean extends JobDetail
|
||||
implements BeanNameAware, ApplicationContextAware, InitializingBean {
|
||||
|
||||
|
@ -81,7 +82,7 @@ public class JobDetailBean extends JobDetail
|
|||
* to adapt the given job class to the Quartz Job interface.
|
||||
*/
|
||||
@Override
|
||||
public Class getJobClass() {
|
||||
public Class<?> getJobClass() {
|
||||
return (this.actualJobClass != null ? this.actualJobClass : super.getJobClass());
|
||||
}
|
||||
|
||||
|
@ -108,9 +109,9 @@ public class JobDetailBean extends JobDetail
|
|||
* @see SchedulerFactoryBean#setJobListeners
|
||||
* @see org.quartz.JobListener#getName
|
||||
*/
|
||||
public void setJobListenerNames(String[] names) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
addJobListener(names[i]);
|
||||
public void setJobListenerNames(String... names) {
|
||||
for (String name : names) {
|
||||
addJobListener(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod
|
|||
* @see SchedulerFactoryBean#setJobListeners
|
||||
* @see org.quartz.JobListener#getName
|
||||
*/
|
||||
public void setJobListenerNames(String[] names) {
|
||||
public void setJobListenerNames(String... names) {
|
||||
this.jobListenerNames = names;
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* to jobs defined directly on this SchedulerFactoryBean.
|
||||
* @see org.quartz.xml.XMLSchedulingDataProcessor
|
||||
*/
|
||||
public void setJobSchedulingDataLocations(String[] jobSchedulingDataLocations) {
|
||||
public void setJobSchedulingDataLocations(String... jobSchedulingDataLocations) {
|
||||
this.jobSchedulingDataLocations = jobSchedulingDataLocations;
|
||||
}
|
||||
|
||||
|
@ -143,9 +143,8 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* @see org.quartz.JobDetail
|
||||
* @see JobDetailBean
|
||||
* @see JobDetailAwareTrigger
|
||||
* @see org.quartz.Trigger#setJobName
|
||||
*/
|
||||
public void setJobDetails(JobDetail[] jobDetails) {
|
||||
public void setJobDetails(JobDetail... jobDetails) {
|
||||
// Use modifiable ArrayList here, to allow for further adding of
|
||||
// JobDetail objects during autodetection of JobDetailAwareTriggers.
|
||||
this.jobDetails = new ArrayList<JobDetail>(Arrays.asList(jobDetails));
|
||||
|
@ -157,7 +156,6 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* @param calendars Map with calendar names as keys as Calendar
|
||||
* objects as values
|
||||
* @see org.quartz.Calendar
|
||||
* @see org.quartz.Trigger#setCalendarName
|
||||
*/
|
||||
public void setCalendars(Map<String, Calendar> calendars) {
|
||||
this.calendars = calendars;
|
||||
|
@ -176,7 +174,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* @see CronTriggerBean
|
||||
* @see SimpleTriggerBean
|
||||
*/
|
||||
public void setTriggers(Trigger[] triggers) {
|
||||
public void setTriggers(Trigger... triggers) {
|
||||
this.triggers = Arrays.asList(triggers);
|
||||
}
|
||||
|
||||
|
@ -184,7 +182,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
/**
|
||||
* Specify Quartz SchedulerListeners to be registered with the Scheduler.
|
||||
*/
|
||||
public void setSchedulerListeners(SchedulerListener[] schedulerListeners) {
|
||||
public void setSchedulerListeners(SchedulerListener... schedulerListeners) {
|
||||
this.schedulerListeners = schedulerListeners;
|
||||
}
|
||||
|
||||
|
@ -192,7 +190,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* Specify global Quartz JobListeners to be registered with the Scheduler.
|
||||
* Such JobListeners will apply to all Jobs in the Scheduler.
|
||||
*/
|
||||
public void setGlobalJobListeners(JobListener[] globalJobListeners) {
|
||||
public void setGlobalJobListeners(JobListener... globalJobListeners) {
|
||||
this.globalJobListeners = globalJobListeners;
|
||||
}
|
||||
|
||||
|
@ -200,11 +198,12 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* Specify named Quartz JobListeners to be registered with the Scheduler.
|
||||
* Such JobListeners will only apply to Jobs that explicitly activate
|
||||
* them via their name.
|
||||
* <p>Note that non-global JobListeners are not supported on Quartz 2.x -
|
||||
* manually register a Matcher against the Quartz ListenerManager instead.
|
||||
* @see org.quartz.JobListener#getName
|
||||
* @see org.quartz.JobDetail#addJobListener
|
||||
* @see JobDetailBean#setJobListenerNames
|
||||
*/
|
||||
public void setJobListeners(JobListener[] jobListeners) {
|
||||
public void setJobListeners(JobListener... jobListeners) {
|
||||
this.jobListeners = jobListeners;
|
||||
}
|
||||
|
||||
|
@ -212,7 +211,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* Specify global Quartz TriggerListeners to be registered with the Scheduler.
|
||||
* Such TriggerListeners will apply to all Triggers in the Scheduler.
|
||||
*/
|
||||
public void setGlobalTriggerListeners(TriggerListener[] globalTriggerListeners) {
|
||||
public void setGlobalTriggerListeners(TriggerListener... globalTriggerListeners) {
|
||||
this.globalTriggerListeners = globalTriggerListeners;
|
||||
}
|
||||
|
||||
|
@ -220,12 +219,13 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
|
|||
* Specify named Quartz TriggerListeners to be registered with the Scheduler.
|
||||
* Such TriggerListeners will only apply to Triggers that explicitly activate
|
||||
* them via their name.
|
||||
* <p>Note that non-global TriggerListeners are not supported on Quartz 2.x -
|
||||
* manually register a Matcher against the Quartz ListenerManager instead.
|
||||
* @see org.quartz.TriggerListener#getName
|
||||
* @see org.quartz.Trigger#addTriggerListener
|
||||
* @see CronTriggerBean#setTriggerListenerNames
|
||||
* @see SimpleTriggerBean#setTriggerListenerNames
|
||||
*/
|
||||
public void setTriggerListeners(TriggerListener[] triggerListeners) {
|
||||
public void setTriggerListeners(TriggerListener... triggerListeners) {
|
||||
this.triggerListeners = triggerListeners;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.scheduling.quartz;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -114,9 +113,9 @@ public class SimpleTriggerBean extends SimpleTrigger
|
|||
* @see SchedulerFactoryBean#setTriggerListeners
|
||||
* @see org.quartz.TriggerListener#getName
|
||||
*/
|
||||
public void setTriggerListenerNames(String[] names) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
addTriggerListener(names[i]);
|
||||
public void setTriggerListenerNames(String... names) {
|
||||
for (String name : names) {
|
||||
addTriggerListener(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,14 +155,14 @@ public class SimpleTriggerBean extends SimpleTrigger
|
|||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws ParseException {
|
||||
public void afterPropertiesSet() {
|
||||
if (getName() == null) {
|
||||
setName(this.beanName);
|
||||
}
|
||||
if (getGroup() == null) {
|
||||
setGroup(Scheduler.DEFAULT_GROUP);
|
||||
}
|
||||
if (getStartTime() == null) {
|
||||
if (this.startDelay > 0 || getStartTime() == null) {
|
||||
setStartTime(new Date(System.currentTimeMillis() + this.startDelay));
|
||||
}
|
||||
if (this.jobDetail != null) {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.scheduling.quartz;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -141,10 +140,20 @@ public class SimpleTriggerFactoryBean implements FactoryBean<SimpleTrigger>, Bea
|
|||
this.jobDataMap.putAll(jobDataAsMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a specific start time for the trigger.
|
||||
* <p>Note that a dynamically computed {@link #setStartDelay} specification
|
||||
* overrides a static timestamp set here.
|
||||
*/
|
||||
public void setStartTime(Date startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the start delay in milliseconds.
|
||||
* <p>The start delay is added to the current system time (when the bean starts)
|
||||
* to control the start time of the trigger.
|
||||
* @see #setStartTime
|
||||
*/
|
||||
public void setStartDelay(long startDelay) {
|
||||
Assert.isTrue(startDelay >= 0, "Start delay cannot be negative");
|
||||
|
@ -202,7 +211,7 @@ public class SimpleTriggerFactoryBean implements FactoryBean<SimpleTrigger>, Bea
|
|||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws ParseException {
|
||||
public void afterPropertiesSet() {
|
||||
if (this.name == null) {
|
||||
this.name = this.beanName;
|
||||
}
|
||||
|
@ -212,12 +221,9 @@ public class SimpleTriggerFactoryBean implements FactoryBean<SimpleTrigger>, Bea
|
|||
if (this.jobDetail != null) {
|
||||
this.jobDataMap.put(JobDetailAwareTrigger.JOB_DETAIL_KEY, this.jobDetail);
|
||||
}
|
||||
if (this.startDelay > 0) {
|
||||
if (this.startDelay > 0 || this.startTime == null) {
|
||||
this.startTime = new Date(System.currentTimeMillis() + this.startDelay);
|
||||
}
|
||||
else if (this.startTime == null) {
|
||||
this.startTime = new Date();
|
||||
}
|
||||
|
||||
/*
|
||||
SimpleTriggerImpl sti = new SimpleTriggerImpl();
|
||||
|
@ -282,4 +288,5 @@ public class SimpleTriggerFactoryBean implements FactoryBean<SimpleTrigger>, Bea
|
|||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class SpringBeanJobFactory extends AdaptableJobFactory implements Schedul
|
|||
* ignored if there is no corresponding property found on the particular
|
||||
* job class (all other unknown properties will still trigger an exception).
|
||||
*/
|
||||
public void setIgnoredUnknownProperties(String[] ignoredUnknownProperties) {
|
||||
public void setIgnoredUnknownProperties(String... ignoredUnknownProperties) {
|
||||
this.ignoredUnknownProperties = ignoredUnknownProperties;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue