/** * Build the actual Trigger -- NOT intended to be invoked by end users, but will rather be invoked by a TriggerBuilder which this ScheduleBuilder is * given to. */ @Override public OperableTrigger instantiate() { CronTriggerImpl ct = new CronTriggerImpl(); try { ct.setCronExpression(cronExpression); } catch (ParseException e) { // all methods of construction ensure the expression is valid by this point... throw new RuntimeException( "CronExpression '" + cronExpression + "' is invalid, which should not be possible, please report bug to Quartz developers."); } ct.setTimeZone(tz); ct.setMisfireInstruction(misfireInstruction); return ct; }
@Override public String toString() { return super.toString() + ", cronEx: " + getCronExpression() + ", timeZone: " + getTimeZone().getID(); } }
/** * <p> * NOT YET IMPLEMENTED: Returns the final time at which the <code>CronTrigger</code> will fire. * </p> * <p> * Note that the return time *may* be in the past. and the date returned is not validated against org.quartz.calendar * </p> */ @Override public Date getFinalFireTime() { Date resultTime; if (getEndTime() != null) { resultTime = getTimeBefore(new Date(getEndTime().getTime() + 1000l)); } else { resultTime = (cronEx == null) ? null : cronEx.getFinalFireTime(); } if ((resultTime != null) && (getStartTime() != null) && (resultTime.before(getStartTime()))) { return null; } return resultTime; }
/** * Returns the next time at which the <code>CronTrigger</code> will fire, after the given time. If * the trigger will not fire after the given time, <code>null</code> will be returned. * * <p>Note that the date returned is NOT validated against the related org.quartz.Calendar (if * any) */ @Override public Date getFireTimeAfter(Date afterTime) { if (afterTime == null) { afterTime = new Date(); } if (getStartTime().after(afterTime)) { afterTime = new Date(getStartTime().getTime() - 1000l); } if (getEndTime() != null && (afterTime.compareTo(getEndTime()) >= 0)) { return null; } Date pot = getTimeAfter(afterTime); if (getEndTime() != null && pot != null && pot.after(getEndTime())) { return null; } return pot; }
/** * Updates the <code>CronTrigger</code>'s state based on the MISFIRE_INSTRUCTION_XXX that was * selected when the <code>CronTrigger</code> was created. * * <p>If the misfire instruction is set to MISFIRE_INSTRUCTION_SMART_POLICY, then the following * scheme will be used: <br> * * <ul> * <li>The instruction will be interpreted as <code>MISFIRE_INSTRUCTION_FIRE_ONCE_NOW</code> * </ul> */ @Override public void updateAfterMisfire(org.quartz.core.Calendar cal) { int instr = getMisfireInstruction(); if (instr == Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY) { return; } if (instr == MISFIRE_INSTRUCTION_SMART_POLICY) { instr = MISFIRE_INSTRUCTION_FIRE_ONCE_NOW; } if (instr == MISFIRE_INSTRUCTION_DO_NOTHING) { Date newFireTime = getFireTimeAfter(new Date()); while (newFireTime != null && cal != null && !cal.isTimeIncluded(newFireTime.getTime())) { newFireTime = getFireTimeAfter(newFireTime); } setNextFireTime(newFireTime); } else if (instr == MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) { setNextFireTime(new Date()); } }
/** * <p> * Called by the scheduler at the time a <code>Trigger</code> is first added to the scheduler, in order to have the <code>Trigger</code> compute its * first fire time, based on any associated calendar. * </p> * <p> * After this method has been called, <code>getNextFireTime()</code> should return a valid answer. * </p> * * @return the first time at which the <code>Trigger</code> will be fired by the scheduler, which is also the same value * <code>getNextFireTime()</code> will return (until after the first firing of the <code>Trigger</code>). </p> */ @Override public Date computeFirstFireTime(org.quartz.core.Calendar calendar) { nextFireTime = getFireTimeAfter(new Date(getStartTime().getTime() - 1000l)); while (nextFireTime != null && calendar != null && !calendar.isTimeIncluded(nextFireTime.getTime())) { nextFireTime = getFireTimeAfter(nextFireTime); } return nextFireTime; }
public void setCronExpression(String cronExpression) throws ParseException { TimeZone origTz = getTimeZone(); this.cronEx = new CronExpression(cronExpression); this.cronEx.setTimeZone(origTz); }
@Override public void setEndTime(Date endTime) { Date sTime = getStartTime(); if (sTime != null && endTime != null && sTime.after(endTime)) { throw new IllegalArgumentException("End time cannot be before start time"); } this.endTime = endTime; }
/** * <p> * Determines whether or not the <code>CronTrigger</code> will occur again. * </p> */ @Override public boolean mayFireAgain() { return (getNextFireTime() != null); }
/** * <p> * Called when the <code>{@link Scheduler}</code> has decided to 'fire' the trigger (execute the associated <code>Job</code>), in order to give the * <code>Trigger</code> a chance to update itself for its next triggering (if any). * </p> * * @see #executionComplete(JobExecutionContext, JobExecutionException) */ @Override public void triggered(org.quartz.core.Calendar calendar) { previousFireTime = nextFireTime; nextFireTime = getFireTimeAfter(nextFireTime); while (nextFireTime != null && calendar != null && !calendar.isTimeIncluded(nextFireTime.getTime())) { nextFireTime = getFireTimeAfter(nextFireTime); } }
@Override public void setStartTime(Date startTime) { if (startTime == null) { throw new IllegalArgumentException("Start time cannot be null"); } Date eTime = getEndTime(); if (eTime != null && startTime != null && eTime.before(startTime)) { throw new IllegalArgumentException("End time cannot be before start time"); } // round off millisecond... // Note timeZone is not needed here as parameter for // Calendar.getInstance(), // since time zone is implicit when using a Date in the setTime method. Calendar cl = Calendar.getInstance(); cl.setTime(startTime); cl.set(Calendar.MILLISECOND, 0); this.startTime = cl.getTime(); }
/** * <p> * Returns the next time at which the <code>CronTrigger</code> will fire, after the given time. If the trigger will not fire after the given time, * <code>null</code> will be returned. * </p> * <p> * Note that the date returned is NOT validated against the related org.quartz.Calendar (if any) * </p> */ @Override public Date getFireTimeAfter(Date afterTime) { if (afterTime == null) { afterTime = new Date(); } if (getStartTime().after(afterTime)) { afterTime = new Date(getStartTime().getTime() - 1000l); } if (getEndTime() != null && (afterTime.compareTo(getEndTime()) >= 0)) { return null; } Date pot = getTimeAfter(afterTime); if (getEndTime() != null && pot != null && pot.after(getEndTime())) { return null; } return pot; }
public void updateAfterMisfire(org.quartz.core.Calendar cal) { int instr = getMisfireInstruction(); Date newFireTime = getFireTimeAfter(new Date()); while (newFireTime != null && cal != null && !cal.isTimeIncluded(newFireTime.getTime())) { newFireTime = getFireTimeAfter(newFireTime); setNextFireTime(newFireTime); } else if (instr == MISFIRE_INSTRUCTION_FIRE_ONCE_NOW) { setNextFireTime(new Date());
/** * Called by the scheduler at the time a <code>Trigger</code> is first added to the scheduler, in * order to have the <code>Trigger</code> compute its first fire time, based on any associated * calendar. * * <p>After this method has been called, <code>getNextFireTime()</code> should return a valid * answer. * * @return the first time at which the <code>Trigger</code> will be fired by the scheduler, which * is also the same value <code>getNextFireTime()</code> will return (until after the first * firing of the <code>Trigger</code>). */ @Override public Date computeFirstFireTime(org.quartz.core.Calendar calendar) { nextFireTime = getFireTimeAfter(new Date(getStartTime().getTime() - 1000l)); while (nextFireTime != null && calendar != null && !calendar.isTimeIncluded(nextFireTime.getTime())) { nextFireTime = getFireTimeAfter(nextFireTime); } return nextFireTime; }
public void setCronExpression(String cronExpression) throws ParseException { TimeZone origTz = getTimeZone(); this.cronEx = new CronExpression(cronExpression); this.cronEx.setTimeZone(origTz); }
@Override public void setEndTime(Date endTime) { Date sTime = getStartTime(); if (sTime != null && endTime != null && sTime.after(endTime)) { throw new IllegalArgumentException("End time cannot be before start time"); } this.endTime = endTime; }
/** * <p> * Determines whether or not the <code>CronTrigger</code> will occur again. * </p> */ @Override public boolean mayFireAgain() { return (getNextFireTime() != null); }
/** * <p> * Called when the <code>{@link Scheduler}</code> has decided to 'fire' the trigger (execute the associated <code>Job</code>), in order to give the * <code>Trigger</code> a chance to update itself for its next triggering (if any). * </p> * * @see #executionComplete(JobExecutionContext, JobExecutionException) */ @Override public void triggered(org.quartz.core.Calendar calendar) { previousFireTime = nextFireTime; nextFireTime = getFireTimeAfter(nextFireTime); while (nextFireTime != null && calendar != null && !calendar.isTimeIncluded(nextFireTime.getTime())) { nextFireTime = getFireTimeAfter(nextFireTime); } }
@Override public void setStartTime(Date startTime) { if (startTime == null) { throw new IllegalArgumentException("Start time cannot be null"); } Date eTime = getEndTime(); if (eTime != null && startTime != null && eTime.before(startTime)) { throw new IllegalArgumentException("End time cannot be before start time"); } // round off millisecond... // Note timeZone is not needed here as parameter for // Calendar.getInstance(), // since time zone is implicit when using a Date in the setTime method. Calendar cl = Calendar.getInstance(); cl.setTime(startTime); cl.set(Calendar.MILLISECOND, 0); this.startTime = cl.getTime(); }
/** * Build the actual Trigger -- NOT intended to be invoked by end users, but will rather be invoked by a TriggerBuilder which this ScheduleBuilder is * given to. */ @Override public OperableTrigger instantiate() { CronTriggerImpl ct = new CronTriggerImpl(); try { ct.setCronExpression(cronExpression); } catch (ParseException e) { // all methods of construction ensure the expression is valid by this point... throw new RuntimeException("CronExpression '" + cronExpression + "' is invalid, which should not be possible, please report bug to Quartz developers."); } ct.setTimeZone(tz); ct.setMisfireInstruction(misfireInstruction); return ct; }