Class DailyTimeIntervalTriggerImpl

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Trigger>, DailyTimeIntervalTrigger, CoreTrigger, MutableTrigger, OperableTrigger, Trigger

    public class DailyTimeIntervalTriggerImpl
    extends AbstractTrigger<DailyTimeIntervalTrigger>
    implements DailyTimeIntervalTrigger, CoreTrigger
    A concrete implementation of DailyTimeIntervalTrigger that is used to fire a JobDetail based upon daily repeating time intervals.

    The trigger will fire every N (see setRepeatInterval(int) ) seconds, minutes or hours (see setRepeatIntervalUnit(org.quartz.DateBuilder.IntervalUnit)) during a given time window on specified days of the week.

    For example#1, a trigger can be set to fire every 72 minutes between 8:00 and 11:00 everyday. It's fire times would be 8:00, 9:12, 10:24, then next day would repeat: 8:00, 9:12, 10:24 again.

    For example#2, a trigger can be set to fire every 23 minutes between 9:20 and 16:47 Monday through Friday.

    On each day, the starting fire time is reset to startTimeOfDay value, and then it will add repeatInterval value to it until the endTimeOfDay is reached. If you set daysOfWeek values, then fire time will only occur during those week days period. Again, remember this trigger will reset fire time each day with startTimeOfDay, regardless of your interval or endTimeOfDay!

    The default values for fields if not set are: startTimeOfDay defaults to 00:00:00, the endTimeOfDay default to 23:59:59, and daysOfWeek is default to every day. The startTime default to current time-stamp now, while endTime has not value.

    If startTime is before startTimeOfDay, then startTimeOfDay will be used and startTime has no affect other than to specify the first day of firing. Else if startTime is after startTimeOfDay, then the first fire time for that day will be the next interval after the startTime. For example, if you set startingTimeOfDay=9am, endingTimeOfDay=11am, interval=15 mins, and startTime=9:33am, then the next fire time will be 9:45pm. Note also that if you do not set startTime value, the trigger builder will default to current time, and current time maybe before or after the startTimeOfDay! So be aware how you set your startTime.

    This trigger also supports "repeatCount" feature to end the trigger fire time after a certain number of count is reached. Just as the SimpleTrigger, setting repeatCount=0 means trigger will fire once only! Setting any positive count then the trigger will repeat count + 1 times. Unlike SimpleTrigger, the default value of repeatCount of this trigger is set to REPEAT_INDEFINITELY instead of 0 though.

    Since:
    2.1.0
    Author:
    James House, Zemian Deng <[email protected]>
    See Also:
    DailyTimeIntervalTrigger, DailyTimeIntervalScheduleBuilder, Serialized Form
    • Constructor Detail

      • DailyTimeIntervalTriggerImpl

        public DailyTimeIntervalTriggerImpl()

        Create a DailyTimeIntervalTrigger with no settings.

      • DailyTimeIntervalTriggerImpl

        public DailyTimeIntervalTriggerImpl​(java.lang.String name,
                                            TimeOfDay startTimeOfDay,
                                            TimeOfDay endTimeOfDay,
                                            DateBuilder.IntervalUnit intervalUnit,
                                            int repeatInterval)

        Create a DailyTimeIntervalTrigger that will occur immediately, and repeat at the given interval.

        Parameters:
        startTimeOfDay - The TimeOfDay that the repeating should begin occurring.
        endTimeOfDay - The TimeOfDay that the repeating should stop occurring.
        intervalUnit - The repeat interval unit. The only intervals that are valid for this type of trigger are DateBuilder.IntervalUnit.SECOND, DateBuilder.IntervalUnit.MINUTE, and DateBuilder.IntervalUnit.HOUR.
        Throws:
        java.lang.IllegalArgumentException - if an invalid IntervalUnit is given, or the repeat interval is zero or less.
      • DailyTimeIntervalTriggerImpl

        public DailyTimeIntervalTriggerImpl​(java.lang.String name,
                                            java.lang.String group,
                                            TimeOfDay startTimeOfDay,
                                            TimeOfDay endTimeOfDay,
                                            DateBuilder.IntervalUnit intervalUnit,
                                            int repeatInterval)

        Create a DailyTimeIntervalTrigger that will occur immediately, and repeat at the given interval.

        Parameters:
        startTimeOfDay - The TimeOfDay that the repeating should begin occurring.
        endTimeOfDay - The TimeOfDay that the repeating should stop occurring.
        intervalUnit - The repeat interval unit. The only intervals that are valid for this type of trigger are DateBuilder.IntervalUnit.SECOND, DateBuilder.IntervalUnit.MINUTE, and DateBuilder.IntervalUnit.HOUR.
        Throws:
        java.lang.IllegalArgumentException - if an invalid IntervalUnit is given, or the repeat interval is zero or less.
      • DailyTimeIntervalTriggerImpl

        public DailyTimeIntervalTriggerImpl​(java.lang.String name,
                                            java.util.Date startTime,
                                            java.util.Date endTime,
                                            TimeOfDay startTimeOfDay,
                                            TimeOfDay endTimeOfDay,
                                            DateBuilder.IntervalUnit intervalUnit,
                                            int repeatInterval)

        Create a DailyTimeIntervalTrigger that will occur at the given time, and repeat at the given interval until the given end time.

        Parameters:
        startTime - A Date set to the time for the Trigger to fire.
        endTime - A Date set to the time for the Trigger to quit repeat firing.
        startTimeOfDay - The TimeOfDay that the repeating should begin occurring.
        endTimeOfDay - The TimeOfDay that the repeating should stop occurring.
        intervalUnit - The repeat interval unit. The only intervals that are valid for this type of trigger are DateBuilder.IntervalUnit.SECOND, DateBuilder.IntervalUnit.MINUTE, and DateBuilder.IntervalUnit.HOUR.
        repeatInterval - The number of milliseconds to pause between the repeat firing.
        Throws:
        java.lang.IllegalArgumentException - if an invalid IntervalUnit is given, or the repeat interval is zero or less.
      • DailyTimeIntervalTriggerImpl

        public DailyTimeIntervalTriggerImpl​(java.lang.String name,
                                            java.lang.String group,
                                            java.util.Date startTime,
                                            java.util.Date endTime,
                                            TimeOfDay startTimeOfDay,
                                            TimeOfDay endTimeOfDay,
                                            DateBuilder.IntervalUnit intervalUnit,
                                            int repeatInterval)

        Create a DailyTimeIntervalTrigger that will occur at the given time, and repeat at the given interval until the given end time.

        Parameters:
        startTime - A Date set to the time for the Trigger to fire.
        endTime - A Date set to the time for the Trigger to quit repeat firing.
        startTimeOfDay - The TimeOfDay that the repeating should begin occurring.
        endTimeOfDay - The TimeOfDay that the repeating should stop occurring.
        intervalUnit - The repeat interval unit. The only intervals that are valid for this type of trigger are DateBuilder.IntervalUnit.SECOND, DateBuilder.IntervalUnit.MINUTE, and DateBuilder.IntervalUnit.HOUR.
        repeatInterval - The number of milliseconds to pause between the repeat firing.
        Throws:
        java.lang.IllegalArgumentException - if an invalid IntervalUnit is given, or the repeat interval is zero or less.
      • DailyTimeIntervalTriggerImpl

        public DailyTimeIntervalTriggerImpl​(java.lang.String name,
                                            java.lang.String group,
                                            java.lang.String jobName,
                                            java.lang.String jobGroup,
                                            java.util.Date startTime,
                                            java.util.Date endTime,
                                            TimeOfDay startTimeOfDay,
                                            TimeOfDay endTimeOfDay,
                                            DateBuilder.IntervalUnit intervalUnit,
                                            int repeatInterval)

        Create a DailyTimeIntervalTrigger that will occur at the given time, fire the identified Job and repeat at the given interval until the given end time.

        Parameters:
        startTime - A Date set to the time for the Trigger to fire.
        endTime - A Date set to the time for the Trigger to quit repeat firing.
        startTimeOfDay - The TimeOfDay that the repeating should begin occurring.
        endTimeOfDay - The TimeOfDay that the repeating should stop occurring.
        intervalUnit - The repeat interval unit. The only intervals that are valid for this type of trigger are DateBuilder.IntervalUnit.SECOND, DateBuilder.IntervalUnit.MINUTE, and DateBuilder.IntervalUnit.HOUR.
        repeatInterval - The number of milliseconds to pause between the repeat firing.
        Throws:
        java.lang.IllegalArgumentException - if an invalid IntervalUnit is given, or the repeat interval is zero or less.
    • Method Detail

      • getStartTime

        public java.util.Date getStartTime()

        Get the time at which the DailyTimeIntervalTrigger should occur. It defaults to the getStartTimeOfDay of current day.

        Specified by:
        getStartTime in interface Trigger
      • setStartTime

        public void setStartTime​(java.util.Date startTime)

        Set the time at which the DailyTimeIntervalTrigger should occur.

        Specified by:
        setStartTime in interface MutableTrigger
        Throws:
        java.lang.IllegalArgumentException - if startTime is null.
      • getEndTime

        public java.util.Date getEndTime()

        Get the time at which the DailyTimeIntervalTrigger should quit repeating.

        Specified by:
        getEndTime in interface Trigger
        See Also:
        getFinalFireTime()
      • getRepeatInterval

        public int getRepeatInterval()
        Description copied from interface: DailyTimeIntervalTrigger

        Get 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:
        getRepeatInterval in interface DailyTimeIntervalTrigger
      • setRepeatInterval

        public void setRepeatInterval​(int repeatInterval)

        set the time interval that will be added to the DailyTimeIntervalTrigger'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
      • setTimesTriggered

        public void setTimesTriggered​(int timesTriggered)

        Set the number of times the DailyTimeIntervalTrigger has already fired.

      • updateAfterMisfire

        public void updateAfterMisfire​(Calendar cal)

        Updates the DailyTimeIntervalTrigger's state based on the MISFIRE_INSTRUCTION_XXX that was selected when the DailyTimeIntervalTrigger was 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:
        updateAfterMisfire in interface OperableTrigger
      • computeFirstFireTime

        public java.util.Date computeFirstFireTime​(Calendar calendar)

        Called by the scheduler at the time a Trigger is first added to the scheduler, in order to have the Trigger compute its first fire time, based on any associated calendar.

        After this method has been called, getNextFireTime() should return a valid answer.

        Specified by:
        computeFirstFireTime in interface OperableTrigger
        Returns:
        the first time at which the Trigger will be fired by the scheduler, which is also the same value getNextFireTime() will return (until after the first firing of the Trigger).
      • getNextFireTime

        public java.util.Date getNextFireTime()

        Returns the next time at which the Trigger is scheduled to fire. If the trigger will not fire again, null will 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 Trigger has been added to the scheduler.

        Specified by:
        getNextFireTime in interface Trigger
        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 DailyTimeIntervalTrigger fired. If the trigger has not yet fired, null will be returned.

        Specified by:
        getPreviousFireTime in interface Trigger
      • setNextFireTime

        public void setNextFireTime​(java.util.Date nextFireTime)

        Set the next time at which the DailyTimeIntervalTrigger should fire.

        This method should not be invoked by client code.

        Specified by:
        setNextFireTime in interface OperableTrigger
      • setPreviousFireTime

        public void setPreviousFireTime​(java.util.Date previousFireTime)

        Set the previous time at which the DailyTimeIntervalTrigger fired.

        This method should not be invoked by client code.

        Specified by:
        setPreviousFireTime in interface OperableTrigger
      • getFireTimeAfter

        public java.util.Date getFireTimeAfter​(java.util.Date afterTime)

        Returns the next time at which the DailyTimeIntervalTrigger will fire, after the given time. If the trigger will not fire after the given time, null will be returned.

        Specified by:
        getFireTimeAfter in interface Trigger
      • getFinalFireTime

        public java.util.Date getFinalFireTime()

        Returns the final time at which the DailyTimeIntervalTrigger will fire, if there is no end time set, null will be returned.

        Note that the return time may be in the past.

        Specified by:
        getFinalFireTime in interface Trigger
      • mayFireAgain

        public boolean mayFireAgain()

        Determines whether or not the DailyTimeIntervalTrigger will occur again.

        Specified by:
        mayFireAgain in interface Trigger
      • getDaysOfWeek

        public java.util.Set<java.lang.Integer> getDaysOfWeek()
        The days of the week upon which to fire.
        Specified by:
        getDaysOfWeek in interface DailyTimeIntervalTrigger
        Returns:
        a Set containing the integers representing the days of the week, per the values 1-7 as defined by Calendar.SUNDAY - Calendar.SATURDAY.
      • setDaysOfWeek

        public void setDaysOfWeek​(java.util.Set<java.lang.Integer> daysOfWeek)
      • setStartTimeOfDay

        public void setStartTimeOfDay​(TimeOfDay startTimeOfDay)
      • setEndTimeOfDay

        public void setEndTimeOfDay​(TimeOfDay endTimeOfDay)
      • hasAdditionalProperties

        public boolean hasAdditionalProperties()
        This trigger has no additional properties besides what's defined in this class.
        Specified by:
        hasAdditionalProperties in interface CoreTrigger
      • setRepeatCount

        public void setRepeatCount​(int repeatCount)