Class CalendarIntervalTriggerImpl
- java.lang.Object
-
- org.quartz.impl.triggers.AbstractTrigger<CalendarIntervalTrigger>
-
- org.quartz.impl.triggers.CalendarIntervalTriggerImpl
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.lang.Comparable<Trigger>,CalendarIntervalTrigger,CoreTrigger,MutableTrigger,OperableTrigger,Trigger
public class CalendarIntervalTriggerImpl extends AbstractTrigger<CalendarIntervalTrigger> implements CalendarIntervalTrigger, CoreTrigger
A concrete
that is used to fire aTriggerbased upon repeating calendar time intervals.JobDetailThe trigger will fire every N (see
setRepeatInterval(int)) units of calendar time (seesetRepeatIntervalUnit(org.quartz.DateBuilder.IntervalUnit)) as specified in the trigger's definition. This trigger can achieve schedules that are not possible withSimpleTrigger(e.g because months are not a fixed number of seconds) orCronTrigger(e.g. because "every 5 months" is not an even divisor of 12).If you use an interval unit of
MONTHthen care should be taken when setting astartTimevalue that is on a day near the end of the month. For example, if you choose a start time that occurs on January 31st, and have a trigger with unitMONTHand interval1, then the next fire time will be February 28th, and the next time after that will be March 28th - and essentially each subsequent firing will occur on the 28th of the month, even if a 31st day exists. If you want a trigger that always fires on the last day of the month - regardless of the number of days in the month, you should useCronTrigger.- Since:
- 1.7
- Author:
- James House
- See Also:
Trigger,CronTrigger,SimpleTrigger,TriggerUtils, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.quartz.Trigger
Trigger.CompletedExecutionInstruction, Trigger.TriggerState, Trigger.TriggerTimeComparator
-
-
Field Summary
-
Fields inherited from interface org.quartz.CalendarIntervalTrigger
MISFIRE_INSTRUCTION_DO_NOTHING, MISFIRE_INSTRUCTION_FIRE_ONCE_NOW
-
Fields inherited from interface org.quartz.Trigger
DEFAULT_PRIORITY, MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY, MISFIRE_INSTRUCTION_SMART_POLICY
-
-
Constructor Summary
Constructors Constructor Description CalendarIntervalTriggerImpl()Create aDateIntervalTriggerwith no settings.CalendarIntervalTriggerImpl(java.lang.String name, java.lang.String group, java.lang.String jobName, java.lang.String jobGroup, java.util.Date startTime, java.util.Date endTime, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create aDateIntervalTriggerthat will occur at the given time, fire the identifiedJoband repeat at the given interval until the given end time.CalendarIntervalTriggerImpl(java.lang.String name, java.lang.String group, java.util.Date startTime, java.util.Date endTime, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create aDateIntervalTriggerthat will occur at the given time, and repeat at the given interval until the given end time.CalendarIntervalTriggerImpl(java.lang.String name, java.lang.String group, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create aDateIntervalTriggerthat will occur immediately, and repeat at the given interval.CalendarIntervalTriggerImpl(java.lang.String name, java.util.Date startTime, java.util.Date endTime, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create aDateIntervalTriggerthat will occur at the given time, and repeat at the given interval until the given end time.CalendarIntervalTriggerImpl(java.lang.String name, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create aDateIntervalTriggerthat will occur immediately, and repeat at the given interval.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.DatecomputeFirstFireTime(Calendar calendar)Called by the scheduler at the time aTriggeris first added to the scheduler, in order to have theTriggercompute its first fire time, based on any associated calendar.java.util.DategetEndTime()Get the time at which theDateIntervalTriggershould quit repeating.java.util.DategetFinalFireTime()Returns the final time at which theDateIntervalTriggerwill fire, if there is no end time set, null will be returned.java.util.DategetFireTimeAfter(java.util.Date afterTime)Returns the next time at which theDateIntervalTriggerwill fire, after the given time.protected java.util.DategetFireTimeAfter(java.util.Date afterTime, boolean ignoreEndTime)java.util.DategetNextFireTime()Returns the next time at which theTriggeris scheduled to fire.java.util.DategetPreviousFireTime()Returns the previous time at which theDateIntervalTriggerfired.intgetRepeatInterval()Get the time interval that will be added to theDateIntervalTrigger's fire time (in the set repeat interval unit) in order to calculate the time of the next trigger repeat.DateBuilder.IntervalUnitgetRepeatIntervalUnit()Get the interval unit - the time unit on with the interval applies.ScheduleBuilder<CalendarIntervalTrigger>getScheduleBuilder()Get aScheduleBuilderthat is configured to produce a schedule identical to this trigger's schedule.java.util.DategetStartTime()Get the time at which theDateIntervalTriggershould occur.intgetTimesTriggered()Get the number of times theDateIntervalTriggerhas already fired.java.util.TimeZonegetTimeZone()Gets the time zone within which time calculations related to this trigger will be performed.booleanhasAdditionalProperties()booleanisPreserveHourOfDayAcrossDaylightSavings()If intervals are a day or greater, this property (set to true) will cause the firing of the trigger to always occur at the same time of day, (the time of day of the startTime) regardless of daylight saving time transitions.booleanisSkipDayIfHourDoesNotExist()If intervals are a day or greater, and preserveHourOfDayAcrossDaylightSavings property is set to true, and the hour of the day does not exist on a given day for which the trigger would fire, the day will be skipped and the trigger advanced a second interval if this property is set to true.booleanmayFireAgain()Determines whether or not theDateIntervalTriggerwill occur again.voidsetEndTime(java.util.Date endTime)Set the time at which theDateIntervalTriggershould quit repeating (and be automatically deleted).voidsetNextFireTime(java.util.Date nextFireTime)Set the next time at which theDateIntervalTriggershould fire.voidsetPreserveHourOfDayAcrossDaylightSavings(boolean preserveHourOfDayAcrossDaylightSavings)voidsetPreviousFireTime(java.util.Date previousFireTime)Set the previous time at which theDateIntervalTriggerfired.voidsetRepeatInterval(int repeatInterval)set the time interval that will be added to theDateIntervalTrigger's fire time (in the set repeat interval unit) in order to calculate the time of the next trigger repeat.voidsetRepeatIntervalUnit(DateBuilder.IntervalUnit intervalUnit)Set the interval unit - the time unit on with the interval applies.voidsetSkipDayIfHourDoesNotExist(boolean skipDayIfHourDoesNotExist)voidsetStartTime(java.util.Date startTime)Set the time at which theDateIntervalTriggershould occur.voidsetTimesTriggered(int timesTriggered)Set the number of times theDateIntervalTriggerhas already fired.voidsetTimeZone(java.util.TimeZone timeZone)Sets the time zone within which time calculations related to this trigger will be performed.voidtriggered(Calendar calendar)Called when thehas decided to 'fire' the trigger (execute the associatedSchedulerJob), in order to give theTriggera chance to update itself for its next triggering (if any).voidupdateAfterMisfire(Calendar cal)Updates theDateIntervalTrigger's state based on the MISFIRE_INSTRUCTION_XXX that was selected when theDateIntervalTriggerwas created.voidupdateWithNewCalendar(Calendar calendar, long misfireThreshold)This method should not be used by the Quartz client.voidvalidate()Validates whether the properties of theJobDetailare valid for submission into aScheduler.protected booleanvalidateMisfireInstruction(int misfireInstruction)-
Methods inherited from class org.quartz.impl.triggers.AbstractTrigger
clone, compareTo, equals, executionComplete, getCalendarName, getDescription, getFireInstanceId, getFullJobName, getFullName, getGroup, getJobDataMap, getJobGroup, getJobKey, getJobName, getKey, getMisfireInstruction, getName, getPriority, getTriggerBuilder, hashCode, setCalendarName, setDescription, setFireInstanceId, setGroup, setJobDataMap, setJobGroup, setJobKey, setJobName, setKey, setMisfireInstruction, setName, setPriority, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.quartz.CalendarIntervalTrigger
getTriggerBuilder
-
Methods inherited from interface org.quartz.Trigger
compareTo, equals, getCalendarName, getDescription, getJobDataMap, getJobKey, getKey, getMisfireInstruction, getPriority
-
-
-
-
Constructor Detail
-
CalendarIntervalTriggerImpl
public CalendarIntervalTriggerImpl()
Create a
DateIntervalTriggerwith no settings.
-
CalendarIntervalTriggerImpl
public CalendarIntervalTriggerImpl(java.lang.String name, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create a
DateIntervalTriggerthat will occur immediately, and repeat at the given interval.
-
CalendarIntervalTriggerImpl
public CalendarIntervalTriggerImpl(java.lang.String name, java.lang.String group, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create a
DateIntervalTriggerthat will occur immediately, and repeat at the given interval.
-
CalendarIntervalTriggerImpl
public CalendarIntervalTriggerImpl(java.lang.String name, java.util.Date startTime, java.util.Date endTime, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create a
DateIntervalTriggerthat will occur at the given time, and repeat at the given interval until the given end time.- Parameters:
startTime- ADateset to the time for theTriggerto fire.endTime- ADateset to the time for theTriggerto quit repeat firing.intervalUnit- The repeat interval unit (minutes, days, months, etc).repeatInterval- The number of milliseconds to pause between the repeat firing.
-
CalendarIntervalTriggerImpl
public CalendarIntervalTriggerImpl(java.lang.String name, java.lang.String group, java.util.Date startTime, java.util.Date endTime, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create a
DateIntervalTriggerthat will occur at the given time, and repeat at the given interval until the given end time.- Parameters:
startTime- ADateset to the time for theTriggerto fire.endTime- ADateset to the time for theTriggerto quit repeat firing.intervalUnit- The repeat interval unit (minutes, days, months, etc).repeatInterval- The number of milliseconds to pause between the repeat firing.
-
CalendarIntervalTriggerImpl
public CalendarIntervalTriggerImpl(java.lang.String name, java.lang.String group, java.lang.String jobName, java.lang.String jobGroup, java.util.Date startTime, java.util.Date endTime, DateBuilder.IntervalUnit intervalUnit, int repeatInterval)Create a
DateIntervalTriggerthat will occur at the given time, fire the identifiedJoband repeat at the given interval until the given end time.- Parameters:
startTime- ADateset to the time for theTriggerto fire.endTime- ADateset to the time for theTriggerto quit repeat firing.intervalUnit- The repeat interval unit (minutes, days, months, etc).repeatInterval- The number of milliseconds to pause between the repeat firing.
-
-
Method Detail
-
getStartTime
public java.util.Date getStartTime()
Get the time at which the
DateIntervalTriggershould occur.- Specified by:
getStartTimein interfaceTrigger
-
setStartTime
public void setStartTime(java.util.Date startTime)
Set the time at which the
DateIntervalTriggershould occur.- Specified by:
setStartTimein interfaceMutableTrigger- Throws:
java.lang.IllegalArgumentException- if startTime isnull.
-
getEndTime
public java.util.Date getEndTime()
Get the time at which the
DateIntervalTriggershould quit repeating.- Specified by:
getEndTimein interfaceTrigger- See Also:
getFinalFireTime()
-
setEndTime
public void setEndTime(java.util.Date endTime)
Set the time at which the
DateIntervalTriggershould quit repeating (and be automatically deleted).- Specified by:
setEndTimein interfaceMutableTrigger- Throws:
java.lang.IllegalArgumentException- if endTime is before start time.- See Also:
TriggerUtils.computeEndTimeToAllowParticularNumberOfFirings(org.quartz.spi.OperableTrigger, org.quartz.Calendar, int)
-
getRepeatIntervalUnit
public DateBuilder.IntervalUnit getRepeatIntervalUnit()
Description copied from interface:CalendarIntervalTriggerGet the interval unit - the time unit on with the interval applies.
- Specified by:
getRepeatIntervalUnitin interfaceCalendarIntervalTrigger
-
setRepeatIntervalUnit
public void setRepeatIntervalUnit(DateBuilder.IntervalUnit intervalUnit)
Set the interval unit - the time unit on with the interval applies.
-
getRepeatInterval
public int getRepeatInterval()
Description copied from interface:CalendarIntervalTriggerGet the time interval that will be added to the
DateIntervalTrigger's fire time (in the set repeat interval unit) in order to calculate the time of the next trigger repeat.- Specified by:
getRepeatIntervalin interfaceCalendarIntervalTrigger
-
setRepeatInterval
public void setRepeatInterval(int repeatInterval)
set the time interval that will be added to the
DateIntervalTrigger's fire time (in the set repeat interval unit) in order to calculate the time of the next trigger repeat.- Throws:
java.lang.IllegalArgumentException- if repeatInterval is < 1
-
getTimeZone
public java.util.TimeZone getTimeZone()
Description copied from interface:CalendarIntervalTriggerGets the time zone within which time calculations related to this trigger will be performed.
If null, the system default TimeZone will be used.
- Specified by:
getTimeZonein interfaceCalendarIntervalTrigger
-
setTimeZone
public void setTimeZone(java.util.TimeZone timeZone)
Sets the time zone within which time calculations related to this trigger will be performed.
- Parameters:
timeZone- the desired TimeZone, or null for the system default.
-
isPreserveHourOfDayAcrossDaylightSavings
public boolean isPreserveHourOfDayAcrossDaylightSavings()
If intervals are a day or greater, this property (set to true) will cause the firing of the trigger to always occur at the same time of day, (the time of day of the startTime) regardless of daylight saving time transitions. Default value is false.For example, without the property set, your trigger may have a start time of 9:00 am on March 1st, and a repeat interval of 2 days. But after the daylight saving transition occurs, the trigger may start firing at 8:00 am every other day.
If however, the time of day does not exist on a given day to fire (e.g. 2:00 am in the United States on the days of daylight saving transition), the trigger will go ahead and fire one hour off on that day, and then resume the normal hour on other days. If you wish for the trigger to never fire at the "wrong" hour, then you should set the property skipDayIfHourDoesNotExist.
- Specified by:
isPreserveHourOfDayAcrossDaylightSavingsin interfaceCalendarIntervalTrigger- See Also:
isSkipDayIfHourDoesNotExist(),getStartTime(),getTimeZone()
-
setPreserveHourOfDayAcrossDaylightSavings
public void setPreserveHourOfDayAcrossDaylightSavings(boolean preserveHourOfDayAcrossDaylightSavings)
-
isSkipDayIfHourDoesNotExist
public boolean isSkipDayIfHourDoesNotExist()
If intervals are a day or greater, and preserveHourOfDayAcrossDaylightSavings property is set to true, and the hour of the day does not exist on a given day for which the trigger would fire, the day will be skipped and the trigger advanced a second interval if this property is set to true. Defaults to false.CAUTION! If you enable this property, and your hour of day happens to be that of daylight savings transition (e.g. 2:00 am in the United States) and the trigger's interval would have had the trigger fire on that day, then you may actually completely miss a firing on the day of transition if that hour of day does not exist on that day! In such a case the next fire time of the trigger will be computed as double (if the interval is 2 days, then a span of 4 days between firings will occur).
- Specified by:
isSkipDayIfHourDoesNotExistin interfaceCalendarIntervalTrigger- See Also:
isPreserveHourOfDayAcrossDaylightSavings()
-
setSkipDayIfHourDoesNotExist
public void setSkipDayIfHourDoesNotExist(boolean skipDayIfHourDoesNotExist)
-
getTimesTriggered
public int getTimesTriggered()
Description copied from interface:CalendarIntervalTriggerGet the number of times the
DateIntervalTriggerhas already fired.- Specified by:
getTimesTriggeredin interfaceCalendarIntervalTrigger
-
setTimesTriggered
public void setTimesTriggered(int timesTriggered)
Set the number of times the
DateIntervalTriggerhas already fired.
-
validateMisfireInstruction
protected boolean validateMisfireInstruction(int misfireInstruction)
- Specified by:
validateMisfireInstructionin classAbstractTrigger<CalendarIntervalTrigger>
-
updateAfterMisfire
public void updateAfterMisfire(Calendar cal)
Updates the
DateIntervalTrigger's state based on the MISFIRE_INSTRUCTION_XXX that was selected when theDateIntervalTriggerwas created.If the misfire instruction is set to MISFIRE_INSTRUCTION_SMART_POLICY, then the following scheme will be used:
- The instruction will be interpreted as
MISFIRE_INSTRUCTION_FIRE_ONCE_NOW
- Specified by:
updateAfterMisfirein interfaceOperableTrigger
- The instruction will be interpreted as
-
triggered
public void triggered(Calendar calendar)
Called when the
has decided to 'fire' the trigger (execute the associatedSchedulerJob), in order to give theTriggera chance to update itself for its next triggering (if any).- Specified by:
triggeredin interfaceOperableTrigger- See Also:
AbstractTrigger.executionComplete(JobExecutionContext, JobExecutionException)
-
updateWithNewCalendar
public void updateWithNewCalendar(Calendar calendar, long misfireThreshold)
Description copied from interface:OperableTriggerThis method should not be used by the Quartz client.
To be implemented by the concrete class.
The implementation should update the
Trigger's state based on the given new version of the associatedCalendar(the state should be updated so that it's next fire time is appropriate given the Calendar's new settings).- Specified by:
updateWithNewCalendarin interfaceOperableTrigger- See Also:
OperableTrigger.updateWithNewCalendar(org.quartz.Calendar, long)
-
computeFirstFireTime
public java.util.Date computeFirstFireTime(Calendar calendar)
Called by the scheduler at the time a
Triggeris first added to the scheduler, in order to have theTriggercompute its first fire time, based on any associated calendar.After this method has been called,
getNextFireTime()should return a valid answer.- Specified by:
computeFirstFireTimein interfaceOperableTrigger- Returns:
- the first time at which the
Triggerwill be fired by the scheduler, which is also the same valuegetNextFireTime()will return (until after the first firing of theTrigger).
-
getNextFireTime
public java.util.Date getNextFireTime()
Returns the next time at which the
Triggeris scheduled to fire. If the trigger will not fire again,nullwill be returned. Note that the time returned can possibly be in the past, if the time that was computed for the trigger to next fire has already arrived, but the scheduler has not yet been able to fire the trigger (which would likely be due to lack of resources e.g. threads).The value returned is not guaranteed to be valid until after the
Triggerhas been added to the scheduler.- Specified by:
getNextFireTimein interfaceTrigger- See Also:
TriggerUtils.computeFireTimesBetween(org.quartz.spi.OperableTrigger, Calendar, java.util.Date, java.util.Date)
-
getPreviousFireTime
public java.util.Date getPreviousFireTime()
Returns the previous time at which the
DateIntervalTriggerfired. If the trigger has not yet fired,nullwill be returned.- Specified by:
getPreviousFireTimein interfaceTrigger
-
setNextFireTime
public void setNextFireTime(java.util.Date nextFireTime)
Set the next time at which the
DateIntervalTriggershould fire.This method should not be invoked by client code.
- Specified by:
setNextFireTimein interfaceOperableTrigger
-
setPreviousFireTime
public void setPreviousFireTime(java.util.Date previousFireTime)
Set the previous time at which the
DateIntervalTriggerfired.This method should not be invoked by client code.
- Specified by:
setPreviousFireTimein interfaceOperableTrigger
-
getFireTimeAfter
public java.util.Date getFireTimeAfter(java.util.Date afterTime)
Returns the next time at which the
DateIntervalTriggerwill fire, after the given time. If the trigger will not fire after the given time,nullwill be returned.- Specified by:
getFireTimeAfterin interfaceTrigger
-
getFireTimeAfter
protected java.util.Date getFireTimeAfter(java.util.Date afterTime, boolean ignoreEndTime)
-
getFinalFireTime
public java.util.Date getFinalFireTime()
Returns the final time at which the
DateIntervalTriggerwill fire, if there is no end time set, null will be returned.Note that the return time may be in the past.
- Specified by:
getFinalFireTimein interfaceTrigger
-
mayFireAgain
public boolean mayFireAgain()
Determines whether or not the
DateIntervalTriggerwill occur again.- Specified by:
mayFireAgainin interfaceTrigger
-
validate
public void validate() throws SchedulerExceptionValidates whether the properties of the
JobDetailare valid for submission into aScheduler.- Specified by:
validatein interfaceOperableTrigger- Overrides:
validatein classAbstractTrigger<CalendarIntervalTrigger>- Throws:
java.lang.IllegalStateException- if a required property (such as Name, Group, Class) is not set.SchedulerException
-
getScheduleBuilder
public ScheduleBuilder<CalendarIntervalTrigger> getScheduleBuilder()
Get aScheduleBuilderthat is configured to produce a schedule identical to this trigger's schedule.- Specified by:
getScheduleBuilderin interfaceTrigger- Specified by:
getScheduleBuilderin classAbstractTrigger<CalendarIntervalTrigger>- See Also:
AbstractTrigger.getTriggerBuilder()
-
hasAdditionalProperties
public boolean hasAdditionalProperties()
- Specified by:
hasAdditionalPropertiesin interfaceCoreTrigger
-
-