Class CronTriggerImpl

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

public class CronTriggerImpl extends AbstractTrigger implements CronTrigger
A concrete Trigger that is used to fire a JobDetail at given moments in time, defined with Unix 'cron-like' definitions.
Author:
Sharada Jambula, James House, Contributions from Mads Henderson
See Also:
  • Constructor Details

    • CronTriggerImpl

      public CronTriggerImpl()
      Create a CronTrigger with no settings.

      The start-time will also be set to the current time, and the time zone will be set the the system's default time zone.

  • Method Details

    • clone

      public Object clone()
      Specified by:
      clone in interface MutableTrigger
      Overrides:
      clone in class AbstractTrigger
    • setCronExpression

      public void setCronExpression(String cronExpression) throws ParseException
      Throws:
      ParseException
    • getCronExpression

      public String getCronExpression()
      Specified by:
      getCronExpression in interface CronTrigger
    • setCronExpression

      public void setCronExpression(CronExpression cronExpression)
      Set the CronExpression to the given one. The TimeZone on the passed-in CronExpression over-rides any that was already set on the Trigger.
      Parameters:
      cronExpression -
    • getStartTime

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

      public void setStartTime(Date startTime)
      Description copied from interface: MutableTrigger
      The time at which the trigger's scheduling should start. May or may not be the first actual fire time of the trigger, depending upon the type of trigger and the settings of the other properties of the trigger. However the first actual first time will not be before this date.

      Setting a value in the past may cause a new trigger to compute a first fire time that is in the past, which may cause an immediate misfire of the trigger.

      Specified by:
      setStartTime in interface MutableTrigger
    • getEndTime

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

      public void setEndTime(Date endTime)
      Description copied from interface: MutableTrigger
      Set the time at which the Trigger should quit repeating - regardless of any remaining repeats (based on the trigger's particular repeat settings).
      Specified by:
      setEndTime in interface MutableTrigger
      See Also:
      • invalid @see
        TriggerUtils#computeEndTimeToAllowParticularNumberOfFirings(Trigger, Calendar, int)
    • 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, org.quartz.core.Calendar, Date, Date)
    • getPreviousFireTime

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

      public void setNextFireTime(Date nextFireTime)
      Sets the next time at which the CronTrigger will 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 CronTrigger fired.

      This method should not be invoked by client code.

      Specified by:
      setPreviousFireTime in interface OperableTrigger
    • getTimeZone

      public TimeZone getTimeZone()
      Description copied from interface: CronTrigger
      Returns the time zone for which the cronExpression of this CronTrigger will be resolved.
      Specified by:
      getTimeZone in interface CronTrigger
    • setTimeZone

      public void setTimeZone(TimeZone timeZone)
      Sets the time zone for which the cronExpression of this CronTrigger will be resolved.

      If setCronExpression(CronExpression) is called after this method, the TimeZone setting on the CronExpression will "win". However if setCronExpression(String) is called after this method, the time zone applied by this method will remain in effect, since the String cron expression does not carry a time zone!

    • getFireTimeAfter

      public Date getFireTimeAfter(Date afterTime)
      Returns the next time at which the CronTrigger will fire, after the given time. If the trigger will not fire after the given time, null will be returned.

      Note that the date returned is NOT validated against the related org.quartz.Calendar (if any)

      Specified by:
      getFireTimeAfter in interface Trigger
    • getFinalFireTime

      public Date getFinalFireTime()
      NOT YET IMPLEMENTED: Returns the final time at which the CronTrigger will fire.

      Note that the return time *may* be in the past. and the date returned is not validated against org.quartz.calendar

      Specified by:
      getFinalFireTime in interface Trigger
    • mayFireAgain

      public boolean mayFireAgain()
      Determines whether or not the CronTrigger will occur again.
      Specified by:
      mayFireAgain in interface Trigger
    • validateMisfireInstruction

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

      public void updateAfterMisfire(Calendar cal)
      Updates the CronTrigger's state based on the MISFIRE_INSTRUCTION_XXX that was selected when the CronTrigger 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
    • 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).
    • getExpressionSummary

      public String getExpressionSummary()
      Specified by:
      getExpressionSummary in interface CronTrigger
    • toString

      public String toString()
      Overrides:
      toString in class AbstractTrigger