simpletrigger.java
来自「Quartz 是个开源的作业调度框架」· Java 代码 · 共 841 行 · 第 1/2 页
JAVA
841 行
/* * Copyright 2004-2005 OpenSymphony * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. * *//* * Previously Copyright (c) 2001-2004 James House */package org.quartz;import java.util.Date;/** * <p> * A concrete <code>{@link Trigger}</code> that is used to fire a <code>{@link org.quartz.JobDetail}</code> * at a given moment in time, and optionally repeated at a specified interval. * </p> * * @see Trigger * @see CronTrigger * @see TriggerUtils * * @author James House * @author contributions by Lieven Govaerts of Ebitec Nv, Belgium. */public class SimpleTrigger extends Trigger { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constants. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * Instructs the <code>{@link Scheduler}</code> that upon a mis-fire * situation, the <code>{@link SimpleTrigger}</code> wants to be fired * now by <code>Scheduler</code>. * </p> * * <p> * <i>NOTE:</i> This instruction should typically only be used for * 'one-shot' (non-repeating) Triggers. If it is used on a trigger with a * repeat count > 0 then it is equivalent to the instruction <code>{@link #MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT} * </code>. * </p> */ public static final int MISFIRE_INSTRUCTION_FIRE_NOW = 1; /** * <p> * Instructs the <code>{@link Scheduler}</code> that upon a mis-fire * situation, the <code>{@link SimpleTrigger}</code> wants to be * re-scheduled to 'now' (even if the associated <code>{@link Calendar}</code> * excludes 'now') with the repeat count left as-is. * </p> * * <p> * <i>NOTE:</i> Use of this instruction causes the trigger to 'forget' * the start-time and repeat-count that it was originally setup with (this * is only an issue if you for some reason wanted to be able to tell what * the original values were at some later time). * </p> * * <p> * <i>NOTE:</i> This instruction could cause the <code>Trigger</code> * to go to the 'COMPLETE' state after firing 'now', if all the * repeat-fire-times where missed. * </p> */ public static final int MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT = 2; /** * <p> * Instructs the <code>{@link Scheduler}</code> that upon a mis-fire * situation, the <code>{@link SimpleTrigger}</code> wants to be * re-scheduled to 'now' (even if the associated <code>{@link Calendar}</code> * excludes 'now') with the repeat count set to what it would be, if it had * not missed any firings. * </p> * * <p> * <i>NOTE:</i> Use of this instruction causes the trigger to 'forget' * the start-time and repeat-count that it was originally setup with (this * is only an issue if you for some reason wanted to be able to tell what * the original values were at some later time). * </p> * * <p> * <i>NOTE:</i> This instruction could cause the <code>Trigger</code> * to go to the 'COMPLETE' state after firing 'now', if all the * repeat-fire-times where missed. * </p> */ public static final int MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT = 3; /** * <p> * Instructs the <code>{@link Scheduler}</code> that upon a mis-fire * situation, the <code>{@link SimpleTrigger}</code> wants to be * re-scheduled to the next scheduled time after 'now' - taking into * account any associated <code>{@link Calendar}</code>, and with the * repeat count set to what it would be, if it had not missed any firings. * </p> * * <p> * <i>NOTE/WARNING:</i> This instruction could cause the <code>Trigger</code> * to go directly to the 'COMPLETE' state if all fire-times where missed. * </p> */ public static final int MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT = 4; /** * <p> * Instructs the <code>{@link Scheduler}</code> that upon a mis-fire * situation, the <code>{@link SimpleTrigger}</code> wants to be * re-scheduled to the next scheduled time after 'now' - taking into * account any associated <code>{@link Calendar}</code>, and with the * repeat count left unchanged. * </p> * * <p> * <i>NOTE:</i> Use of this instruction causes the trigger to 'forget' * the repeat-count that it was originally setup with (this is only an * issue if you for some reason wanted to be able to tell what the original * values were at some later time). * </p> * * <p> * <i>NOTE/WARNING:</i> This instruction could cause the <code>Trigger</code> * to go directly to the 'COMPLETE' state if all fire-times where missed. * </p> */ public static final int MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT = 5; /** * <p> * Used to indicate the 'repeat count' of the trigger is indefinite. Or in * other words, the trigger should repeat continually until the trigger's * ending timestamp. * </p> */ public static int REPEAT_INDEFINITELY = -1; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Data members. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ private Date startTime = null; private Date endTime = null; private Date nextFireTime = null; private Date previousFireTime = null; private int repeatCount = 0; private long repeatInterval = 0; private int timesTriggered = 0; private boolean complete = false; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constructors. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * Create a <code>SimpleTrigger</code> with no settings. * </p> */ public SimpleTrigger() { super(); } /** * <p> * Create a <code>SimpleTrigger</code> that will occur immediately, and * not repeat. * </p> */ public SimpleTrigger(String name, String group) { this(name, group, new Date(), null, 0, 0); } /** * <p> * Create a <code>SimpleTrigger</code> that will occur immediately, and * repeat at the the given interval the given number of times. * </p> */ public SimpleTrigger(String name, String group, int repeatCount, long repeatInterval) { this(name, group, new Date(), null, repeatCount, repeatInterval); } /** * <p> * Create a <code>SimpleTrigger</code> that will occur at the given time, * and not repeat. * </p> */ public SimpleTrigger(String name, String group, Date startTime) { this(name, group, startTime, null, 0, 0); } /** * <p> * Create a <code>SimpleTrigger</code> that will occur at the given time, * and repeat at the the given interval the given number of times, or until * the given end time. * </p> * * @param startTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to fire. * @param endTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to quit repeat firing. * @param repeatCount * The number of times for the <code>Trigger</code> to repeat * firing, use {@link #REPEAT_INDEFINITELY}for unlimitted times. * @param repeatInterval * The number of milliseconds to pause between the repeat firing. */ public SimpleTrigger(String name, String group, Date startTime, Date endTime, int repeatCount, long repeatInterval) { super(name, group); setStartTime(startTime); setEndTime(endTime); setRepeatCount(repeatCount); setRepeatInterval(repeatInterval); } /** * <p> * Create a <code>SimpleTrigger</code> that will occur at the given time, * fire the identified <code>Job</code> and repeat at the the given * interval the given number of times, or until the given end time. * </p> * * @param startTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to fire. * @param endTime * A <code>Date</code> set to the time for the <code>Trigger</code> * to quit repeat firing. * @param repeatCount * The number of times for the <code>Trigger</code> to repeat * firing, use {@link #REPEAT_INDEFINITELY}for unlimitted times. * @param repeatInterval * The number of milliseconds to pause between the repeat firing. */ public SimpleTrigger(String name, String group, String jobName, String jobGroup, Date startTime, Date endTime, int repeatCount, long repeatInterval) { super(name, group, jobName, jobGroup); setStartTime(startTime); setEndTime(endTime); setRepeatCount(repeatCount); setRepeatInterval(repeatInterval); } /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * Get the time at which the <code>SimpleTrigger</code> should occur. * </p> */ public Date getStartTime() { return startTime; } /** * <p> * Set the time at which the <code>SimpleTrigger</code> should occur. * </p> * * @exception IllegalArgumentException * if startTime is <code>null</code>. */ 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"); this.startTime = startTime; } /** * <p> * Get the time at which the <code>SimpleTrigger</code> should quit * repeating - even if repeastCount isn't yet satisfied. * </p> * * @see #getFinalFireTime() */ public Date getEndTime() { return endTime; } /** * <p> * Set the time at which the <code>SimpleTrigger</code> should quit * repeating (and be automatically deleted). * </p> * * @exception IllegalArgumentException * if endTime is before start time. */ 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> * Get the the number of times the <code>SimpleTrigger</code> should * repeat, after which it will be automatically deleted. * </p> * * @see #REPEAT_INDEFINITELY */ public int getRepeatCount() { return repeatCount; } /** * <p> * Set the the number of time the <code>SimpleTrigger</code> should * repeat, after which it will be automatically deleted. * </p> * * @see #REPEAT_INDEFINITELY * @exception IllegalArgumentException * if repeatCount is < 0 */ public void setRepeatCount(int repeatCount) { if (repeatCount < 0 && repeatCount != REPEAT_INDEFINITELY) throw new IllegalArgumentException( "Repeat count must be >= 0, use the " + "constant REPEAT_INDEFINITELY for infinite."); this.repeatCount = repeatCount; } /** * <p> * Get the the time interval (in milliseconds) at which the <code>SimpleTrigger</code> * should repeat. * </p> */ public long getRepeatInterval() { return repeatInterval; } /** * <p> * Set the the time interval (in milliseconds) at which the <code>SimpleTrigger</code> * should repeat. * </p> * * @exception IllegalArgumentException * if repeatInterval is <= 0 */ public void setRepeatInterval(long repeatInterval) { if (repeatInterval < 0) throw new IllegalArgumentException( "Repeat interval must be >= 0"); this.repeatInterval = repeatInterval; } /** * <p> * Get the number of times the <code>SimpleTrigger</code> has already * fired. * </p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?