From aeef8c87f6fbfc73125a2d44f0fd211dce1d7139 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 4 Jul 2012 23:22:38 +0200 Subject: [PATCH] added "repeatCount" bean property to Quartz SimpleTriggerFactoryBean Issue: SPR-9521 --- .../quartz/CronTriggerFactoryBean.java | 9 +++----- .../quartz/SimpleTriggerFactoryBean.java | 22 +++++++++++++------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java index a8294f05d41..b205e6d73af 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java +++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -56,9 +56,7 @@ import org.springframework.util.ReflectionUtils; * @since 3.1 * @see #setName * @see #setGroup - * @see #setStartTime - * @see #setJobName - * @see #setJobGroup + * @see #setStartDelay * @see #setJobDetail * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#setTriggers * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#setJobDetails @@ -147,10 +145,9 @@ public class CronTriggerFactoryBean implements FactoryBean, BeanNam * Set the start delay in milliseconds. *

The start delay is added to the current system time (when the bean starts) * to control the start time of the trigger. - * @param startDelay the start delay, in milliseconds */ public void setStartDelay(long startDelay) { - Assert.state(startDelay >= 0, "Start delay cannot be negative."); + Assert.isTrue(startDelay >= 0, "Start delay cannot be negative"); this.startDelay = startDelay; } diff --git a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java index c26b0d00424..5baffd047da 100644 --- a/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java +++ b/org.springframework.context.support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -56,9 +56,7 @@ import org.springframework.util.ReflectionUtils; * @since 3.1 * @see #setName * @see #setGroup - * @see #setStartTime - * @see #setJobName - * @see #setJobGroup + * @see #setStartDelay * @see #setJobDetail * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#setTriggers * @see org.springframework.scheduling.quartz.SchedulerFactoryBean#setJobDetails @@ -84,6 +82,8 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea private long repeatInterval; + private int repeatCount = -1; + private int priority; private int misfireInstruction; @@ -145,10 +145,9 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea * Set the start delay in milliseconds. *

The start delay is added to the current system time (when the bean starts) * to control the start time of the trigger. - * @param startDelay the start delay, in milliseconds */ public void setStartDelay(long startDelay) { - Assert.state(startDelay >= 0, "Start delay cannot be negative."); + Assert.isTrue(startDelay >= 0, "Start delay cannot be negative"); this.startDelay = startDelay; } @@ -159,6 +158,14 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea this.repeatInterval = repeatInterval; } + /** + * Specify the number of times this trigger is supposed to fire. + *

Default is to repeat indefinitely. + */ + public void setRepeatCount(int repeatCount) { + this.repeatCount = repeatCount; + } + /** * Specify the priority of this trigger. */ @@ -218,6 +225,7 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea sti.setJobDataMap(this.jobDataMap); sti.setStartTime(this.startTime); sti.setRepeatInterval(this.repeatInterval); + sti.setRepeatCount(this.repeatCount); sti.setPriority(this.priority); sti.setMisfireInstruction(this.misfireInstruction); this.simpleTrigger = sti; @@ -250,7 +258,7 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea pvs.add("jobDataMap", this.jobDataMap); pvs.add("startTime", this.startTime); pvs.add("repeatInterval", this.repeatInterval); - pvs.add("repeatCount", -1); + pvs.add("repeatCount", this.repeatCount); pvs.add("priority", this.priority); pvs.add("misfireInstruction", this.misfireInstruction); bw.setPropertyValues(pvs);