Class SimpleTriggerImpl

java.lang.Object
org.quartz.triggers.AbstractTrigger
org.quartz.triggers.SimpleTriggerImpl
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Trigger>, MutableTrigger, OperableTrigger, SimpleTrigger, Trigger

public class SimpleTriggerImpl extends AbstractTrigger implements SimpleTrigger
A concrete Trigger that is used to fire a JobDetail at a given moment in time, and optionally repeated at a specified interval.
Author:
James House, contributions by Lieven Govaerts of Ebitec Nv, Belgium.
See Also:
  • Constructor Details

    • SimpleTriggerImpl

      public SimpleTriggerImpl()
      Create a SimpleTrigger with no settings.
  • Method Details

    • getStartTime

      public Date getStartTime()
      Get the time at which the SimpleTrigger should occur.
      Specified by:
      getStartTime in interface Trigger
    • setStartTime

      public void setStartTime(Date startTime)
      Set the time at which the SimpleTrigger should occur.
      Specified by:
      setStartTime in interface MutableTrigger
      Throws:
      IllegalArgumentException - if startTime is null.
    • getEndTime

      public Date getEndTime()
      Get the time at which the SimpleTrigger should quit repeating - even if repeastCount isn't yet satisfied.
      Specified by:
      getEndTime in interface Trigger
      See Also:
    • setEndTime

      public void setEndTime(Date endTime)
      Set the time at which the SimpleTrigger should quit repeating (and be automatically deleted).
      Specified by:
      setEndTime in interface MutableTrigger
      Throws:
      IllegalArgumentException - if endTime is before start time.
      See Also:
      • invalid @see
        TriggerUtils#computeEndTimeToAllowParticularNumberOfFirings(Trigger, Calendar, int)
    • getRepeatCount

      public int getRepeatCount()
      Description copied from interface: SimpleTrigger
      Get the the number of times the SimpleTrigger should repeat, after which it will be automatically deleted.
      Specified by:
      getRepeatCount in interface SimpleTrigger
      See Also:
    • setRepeatCount

      public void setRepeatCount(int repeatCount)
      Set the the number of time the SimpleTrigger should repeat, after which it will be automatically deleted.
      Throws:
      IllegalArgumentException - if repeatCount is invalid input: '<' 0
      See Also:
    • getRepeatInterval

      public long getRepeatInterval()
      Description copied from interface: SimpleTrigger
      Get the the time interval (in milliseconds) at which the SimpleTrigger should repeat.
      Specified by:
      getRepeatInterval in interface SimpleTrigger
    • setRepeatInterval

      public void setRepeatInterval(long repeatInterval)
      Set the the time interval (in milliseconds) at which the SimpleTrigger should repeat.
      Throws:
      IllegalArgumentException - if repeatInterval is invalid input: '<'= 0
    • getTimesTriggered

      public int getTimesTriggered()
      Get the number of times the SimpleTrigger has already fired.
      Specified by:
      getTimesTriggered in interface SimpleTrigger
    • setTimesTriggered

      public void setTimesTriggered(int timesTriggered)
      Set the number of times the SimpleTrigger has already fired.
    • validateMisfireInstruction

      protected boolean validateMisfireInstruction(int misfireInstruction)
      Specified by:
      validateMisfireInstruction in class AbstractTrigger
    • updateAfterMisfire

      public void updateAfterMisfire(Calendar cal)
      Updates the SimpleTrigger's state based on the MISFIRE_INSTRUCTION_XXX that was selected when the SimpleTrigger was created.

      If the misfire instruction is set to MISFIRE_INSTRUCTION_SMART_POLICY, then the following scheme will be used:

      • If the Repeat Count is 0, then the instruction will be interpreted as MISFIRE_INSTRUCTION_FIRE_NOW.
      • If the Repeat Count is REPEAT_INDEFINITELY, then the instruction will be interpreted as MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT. WARNING: using MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT with a trigger that has a non-null end-time may cause the trigger to never fire again if the end-time arrived during the misfire time span.
      • If the Repeat Count is > 0, then the instruction will be interpreted as MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT.

      If the misfire instruction is set to Trigger.MISFIRE_INSTRUCTION_SKIP_TO_NEXT_FIRE_AFTER_CURRENT_DATE then the behavior will be identical to

      Specified by:
      updateAfterMisfire in interface OperableTrigger
    • triggered

      public void triggered(Calendar calendar)
      Called when the Scheduler has decided to 'fire' the trigger (execute the associated Job), in order to give the Trigger a chance to update itself for its next triggering (if any).
      Specified by:
      triggered in interface OperableTrigger
      See Also:
    • computeFirstFireTime

      public 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 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:
      • invalid @see
        TriggerUtils#computeFireTimesBetween(Trigger, Calendar, Date, Date)
    • getPreviousFireTime

      public Date getPreviousFireTime()
      Returns the previous time at which the SimpleTrigger fired. If the trigger has not yet fired, null will be returned.
      Specified by:
      getPreviousFireTime in interface Trigger
    • setNextFireTime

      public void setNextFireTime(Date nextFireTime)
      Set the next time at which the SimpleTrigger should fire.

      This method should not be invoked by client code.

      Specified by:
      setNextFireTime in interface OperableTrigger
    • setPreviousFireTime

      public void setPreviousFireTime(Date previousFireTime)
      Set the previous time at which the SimpleTrigger fired.

      This method should not be invoked by client code.

      Specified by:
      setPreviousFireTime in interface OperableTrigger
    • getFireTimeAfter

      public Date getFireTimeAfter(Date afterTime)
      Returns the next time at which the SimpleTrigger 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 Date getFinalFireTime()
      Returns the final time at which the SimpleTrigger will fire, if repeatCount is REPEAT_INDEFINITELY, 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 SimpleTrigger will occur again.
      Specified by:
      mayFireAgain in interface Trigger
    • validate

      public void validate() throws SchedulerException
      Validates whether the properties of the JobDetail are valid for submission into a Scheduler.
      Specified by:
      validate in interface OperableTrigger
      Overrides:
      validate in class AbstractTrigger
      Throws:
      IllegalStateException - if a required property (such as Name, Group, Class) is not set.
      SchedulerException
    • toString

      public String toString()
      Overrides:
      toString in class AbstractTrigger