scheduler.java
来自「Quartz 是个开源的作业调度框架」· Java 代码 · 共 978 行 · 第 1/3 页
JAVA
978 行
/* * 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;import java.util.List;import java.util.Set;import org.quartz.spi.JobFactory;/** * <p> * This is the main interface of a Quartz Scheduler. * </p> * * <p> * A <code>Scheduler</code> maintains a registery of <code>{@link org.quartz.JobDetail}</code> * s and <code>{@link Trigger}</code>s. Once registered, the <code>Scheduler</code> * is responible for executing <code>Job</code> s when their associated * <code>Trigger</code> s fire (when their scheduled time arrives). * </p> * * <p> * <code>Scheduler</code> instances are produced by a <code>{@link SchedulerFactory}</code>. * A scheduler that has already been created/initialized can be found and used * through the same factory that produced it. After a <code>Scheduler</code> * has been created, it is in "stand-by" mode, and must have its * <code>start()</code> method called before it will fire any <code>Job</code>s. * </p> * * <p> * <code>Job</code> s are to be created by the 'client program', by defining * a class that implements the <code>{@link org.quartz.Job}</code> * interface. <code>{@link JobDetail}</code> objects are then created (also * by the client) to define a individual instances of the <code>Job</code>. * <code>JobDetail</code> instances can then be registered with the <code>Scheduler</code> * via the <code>scheduleJob(JobDetail, Trigger)</code> or <code>addJob(JobDetail, boolean)</code> * method. * </p> * * <p> * <code>Trigger</code> s can then be defined to fire individual <code>Job</code> * instances based on given schedules. <code>SimpleTrigger</code> s are most * useful for one-time firings, or firing at an exact moment in time, with N * repeats with a given delay between them. <code>CronTrigger</code> s allow * scheduling based on time of day, day of week, day of month, and month of * year. * </p> * * <p> * <code>Job</code> s and <code>Trigger</code> s have a name and group * associated with them, which should uniquely identify them within a single * <code>{@link Scheduler}</code>. The 'group' feature may be useful for * creating logical groupings or categorizations of <code>Jobs</code> s and * <code>Triggers</code>s. If you don't have need for assigning a group to a * given <code>Jobs</code> of <code>Triggers</code>, then you can use the * <code>DEFAULT_GROUP</code> constant defined on this interface. * </p> * * <p> * Stored <code>Job</code> s can also be 'manually' triggered through the use * of the <code>triggerJob(String jobName, String jobGroup)</code> function. * </p> * * <p> * Client programs may also be interested in the 'listener' interfaces that are * available from Quartz. The <code>{@link JobListener}</code> interface * provides notifications of <code>Job</code> executions. The <code>{@link TriggerListener}</code> * interface provides notifications of <code>Trigger</code> firings. The * <code>{@link SchedulerListener}</code> interface provides notifications of * <code>Scheduler</code> events and errors. * </p> * * <p> * The setup/configuration of a <code>Scheduler</code> instance is very * customizable. Please consult the documentation distributed with Quartz. * </p> * * @see Job * @see JobDetail * @see Trigger * @see JobListener * @see TriggerListener * @see SchedulerListener * * @author James House * @author Sharada Jambula */public interface Scheduler { /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Constants. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * A (possibly) usefull constant that can be used for specifying the group * that <code>Job</code> and <code>Trigger</code> instances belong to. * </p> */ public static final String DEFAULT_GROUP = "DEFAULT"; /** * <p> * A constant <code>Trigger</code> group name used internally by the * scheduler - clients should not use the value of this constant * ("MANUAL_TRIGGER") for thename of a <code>Trigger</code>'s group. * </p> */ public static final String DEFAULT_MANUAL_TRIGGERS = "MANUAL_TRIGGER"; /** * <p> * A constant <code>Trigger</code> group name used internally by the * scheduler - clients should not use the value of this constant * ("RECOVERING_JOBS") for thename of a <code>Trigger</code>'s group. * </p> */ public static final String DEFAULT_RECOVERY_GROUP = "RECOVERING_JOBS"; /** * <p> * A constant <code>Trigger</code> group name used internally by the * scheduler - clients should not use the value of this constant * ("FAILED_OVER_JOBS") for thename of a <code>Trigger</code>'s group. * </p> */ public static final String DEFAULT_FAIL_OVER_GROUP = "FAILED_OVER_JOBS"; /* * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * Interface. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /** * <p> * Returns the name of the <code>Scheduler</code>. * </p> */ public String getSchedulerName() throws SchedulerException; /** * <p> * Returns the instance Id of the <code>Scheduler</code>. * </p> */ public String getSchedulerInstanceId() throws SchedulerException; /** * <p> * Returns the <code>SchedulerContext</code> of the <code>Scheduler</code>. * </p> */ public SchedulerContext getContext() throws SchedulerException; /////////////////////////////////////////////////////////////////////////// /// /// Schedululer State Management Methods /// /////////////////////////////////////////////////////////////////////////// /** * <p> * Starts the <code>Scheduler</code>'s threads that fire <code>{@link Trigger}s</code>. * When a scheduler is first created it is in "stand-by" mode, and will not * fire triggers. The scheduler can also be put into stand-by mode by * calling the <code>standby()</code> method. * </p> * * <p> * The misfire/recovery process will be started, if it is the initial call * to this method on this scheduler instance. * </p> * * @throws SchedulerException * if <code>shutdown()</code> has been called, or there is an * error within the <code>Scheduler</code>. * * @see #standby * @see #shutdown */ public void start() throws SchedulerException; /** * <p> * Temporarily halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>. * </p> * * <p> * When <code>start()</code> is called (to bring the scheduler out of * stand-by mode), trigger misfire instructions will NOT be applied * during the execution of the <code>start()</code> method - any misfires * will be detected immediately afterward (by the <code>JobStore</code>'s * normal process). * </p> * * <p> * The scheduler is not destroyed, and can be re-started at any time. * </p> * * @see #start() * @see #pauseAll() */ public void standby() throws SchedulerException; /** * @deprecated replaced by better-named standby() method. * @see #standby() */ public void pause() throws SchedulerException; /** * <p> * Reports whether the <code>Scheduler</code> is in stand-by mode. * </p> * * @see #standby() * @see #start() */ public boolean isInStandbyMode() throws SchedulerException; /** * @deprecated * @see #isInStandbyMode() */ public boolean isPaused() throws SchedulerException; /** * <p> * Halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>, * and cleans up all resources associated with the Scheduler. Equivalent to * <code>shutdown(false)</code>. * </p> * * <p> * The scheduler cannot be re-started. * </p> * * @see #shutdown(boolean) */ public void shutdown() throws SchedulerException; /** * <p> * Halts the <code>Scheduler</code>'s firing of <code>{@link Trigger}s</code>, * and cleans up all resources associated with the Scheduler. * </p> * * <p> * The scheduler cannot be re-started. * </p> * * @param waitForJobsToComplete * if <code>true</code> the scheduler will not allow this method * to return until all currently executing jobs have completed. * * @see #shutdown */ public void shutdown(boolean waitForJobsToComplete) throws SchedulerException; /** * <p> * Reports whether the <code>Scheduler</code> has been shutdown. * </p> */ public boolean isShutdown() throws SchedulerException; /** * <p> * Get a <code>SchedulerMetaData</code> object describiing the settings * and capabilities of the scheduler instance. * </p> * * <p> * Note that the data returned is an 'instantaneous' snap-shot, and that as * soon as it's returned, the meta data values may be different. * </p> */ public SchedulerMetaData getMetaData() throws SchedulerException; /** * <p> * Return a list of <code>JobExecutionContext</code> objects that * represent all currently executing Jobs. * </p> * * <p> * Note that the list returned is an 'instantaneous' snap-shot, and that as * soon as it's returned, the true list of executing jobs may be different. * Also please read the doc associated with <code>JobExecutionContext</code>- * especially if you're using RMI. * </p> * * @see JobExecutionContext */ public List getCurrentlyExecutingJobs() throws SchedulerException; /** * <p>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?