📄 quartzscheduler.java
字号:
validateState();
if(jobGroup == null)
jobGroup = Scheduler.DEFAULT_GROUP;
return resources.getJobStore().retrieveJob(ctxt, jobName, jobGroup);
}
/**
* <p>
* Get the <code>{@link Trigger}</code> instance with the given name and
* group.
* </p>
*/
public Trigger getTrigger(SchedulingContext ctxt, String triggerName,
String triggerGroup) throws SchedulerException {
validateState();
if(triggerGroup == null)
triggerGroup = Scheduler.DEFAULT_GROUP;
return resources.getJobStore().retrieveTrigger(ctxt, triggerName,
triggerGroup);
}
/**
* <p>
* Get the current state of the identified <code>{@link Trigger}</code>.
* </p>
*
* @see Trigger#STATE_NORMAL
* @see Trigger#STATE_PAUSED
* @see Trigger#STATE_COMPLETE
* @see Trigger#STATE_ERROR
*/
public int getTriggerState(SchedulingContext ctxt, String triggerName,
String triggerGroup) throws SchedulerException {
validateState();
if(triggerGroup == null)
triggerGroup = Scheduler.DEFAULT_GROUP;
return resources.getJobStore().getTriggerState(ctxt, triggerName,
triggerGroup);
}
/**
* <p>
* Add (register) the given <code>Calendar</code> to the Scheduler.
* </p>
*
* @throws SchedulerException
* if there is an internal Scheduler error, or a Calendar with
* the same name already exists, and <code>replace</code> is
* <code>false</code>.
*/
public void addCalendar(SchedulingContext ctxt, String calName,
Calendar calendar, boolean replace, boolean updateTriggers) throws SchedulerException {
validateState();
resources.getJobStore().storeCalendar(ctxt, calName, calendar, replace, updateTriggers);
}
/**
* <p>
* Delete the identified <code>Calendar</code> from the Scheduler.
* </p>
*
* @return true if the Calendar was found and deleted.
* @throws SchedulerException
* if there is an internal Scheduler error.
*/
public boolean deleteCalendar(SchedulingContext ctxt, String calName)
throws SchedulerException {
validateState();
return resources.getJobStore().removeCalendar(ctxt, calName);
}
/**
* <p>
* Get the <code>{@link Calendar}</code> instance with the given name.
* </p>
*/
public Calendar getCalendar(SchedulingContext ctxt, String calName)
throws SchedulerException {
validateState();
return resources.getJobStore().retrieveCalendar(ctxt, calName);
}
/**
* <p>
* Get the names of all registered <code>{@link Calendar}s</code>.
* </p>
*/
public String[] getCalendarNames(SchedulingContext ctxt)
throws SchedulerException {
validateState();
return resources.getJobStore().getCalendarNames(ctxt);
}
/**
* <p>
* Add the given <code>{@link org.quartz.JobListener}</code> to the
* <code>Scheduler</code>'s<i>global</i> list.
* </p>
*
* <p>
* Listeners in the 'global' list receive notification of execution events
* for ALL <code>{@link org.quartz.Job}</code>s.
* </p>
*/
public void addGlobalJobListener(JobListener jobListener) {
if (jobListener.getName() == null
|| jobListener.getName().length() == 0)
throw new IllegalArgumentException(
"JobListener name cannot be empty.");
globalJobListeners.add(jobListener);
}
/**
* <p>
* Add the given <code>{@link org.quartz.JobListener}</code> to the
* <code>Scheduler</code>'s list, of registered <code>JobListener</code>s.
*/
public void addJobListener(JobListener jobListener) {
if (jobListener.getName() == null
|| jobListener.getName().length() == 0)
throw new IllegalArgumentException(
"JobListener name cannot be empty.");
jobListeners.put(jobListener.getName(), jobListener);
}
/**
* <p>
* Remove the given <code>{@link org.quartz.JobListener}</code> from the
* <code>Scheduler</code>'s list of <i>global</i> listeners.
* </p>
*
* @return true if the identifed listener was found in the list, and
* removed.
*/
public boolean removeGlobalJobListener(JobListener jobListener) {
return globalJobListeners.remove(jobListener);
}
/**
* <p>
* Remove the identifed <code>{@link org.quartz.JobListener}</code> from
* the <code>Scheduler</code>'s list of registered listeners.
* </p>
*
* @return true if the identifed listener was found in the list, and
* removed.
*/
public boolean removeJobListener(String name) {
Object o = jobListeners.remove(name);
if (o != null) return true;
return false;
}
/**
* <p>
* Get a List containing all of the <code>{@link org.quartz.JobListener}</code>
* s in the <code>Scheduler</code>'s<i>global</i> list.
* </p>
*/
public List getGlobalJobListeners() {
return new LinkedList(globalJobListeners);
}
/**
* <p>
* Get a Set containing the names of all the <i>non-global</i><code>{@link org.quartz.JobListener}</code>
* s registered with the <code>Scheduler</code>.
* </p>
*/
public Set getJobListenerNames() {
return Collections.unmodifiableSet(jobListeners.keySet());
}
/**
* <p>
* Get the <i>non-global</i><code>{@link org.quartz.JobListener}</code>
* that has the given name.
* </p>
*/
public JobListener getJobListener(String name) {
return (JobListener) jobListeners.get(name);
}
/**
* <p>
* Add the given <code>{@link org.quartz.TriggerListener}</code> to the
* <code>Scheduler</code>'s<i>global</i> list.
* </p>
*
* <p>
* Listeners in the 'global' list receive notification of execution events
* for ALL <code>{@link org.quartz.Trigger}</code>s.
* </p>
*/
public void addGlobalTriggerListener(TriggerListener triggerListener) {
if (triggerListener.getName() == null
|| triggerListener.getName().length() == 0)
throw new IllegalArgumentException(
"TriggerListener name cannot be empty.");
globalTriggerListeners.add(triggerListener);
}
/**
* <p>
* Add the given <code>{@link org.quartz.TriggerListener}</code> to the
* <code>Scheduler</code>'s list, of registered <code>TriggerListener</code>s.
*/
public void addTriggerListener(TriggerListener triggerListener) {
if (triggerListener.getName() == null
|| triggerListener.getName().length() == 0)
throw new IllegalArgumentException(
"TriggerListener name cannot be empty.");
triggerListeners.put(triggerListener.getName(), triggerListener);
}
/**
* <p>
* Remove the given <code>{@link org.quartz.TriggerListener}</code> from
* the <code>Scheduler</code>'s list of <i>global</i> listeners.
* </p>
*
* @return true if the identifed listener was found in the list, and
* removed.
*/
public boolean removeGlobalTriggerListener(TriggerListener triggerListener) {
return globalTriggerListeners.remove(triggerListener);
}
/**
* <p>
* Remove the identifed <code>{@link org.quartz.TriggerListener}</code>
* from the <code>Scheduler</code>'s list of registered listeners.
* </p>
*
* @return true if the identifed listener was found in the list, and
* removed.
*/
public boolean removeTriggerListener(String name) {
Object o = triggerListeners.remove(name);
if (o != null) return true;
return false;
}
/**
* <p>
* Get a list containing all of the <code>{@link org.quartz.TriggerListener}</code>
* s in the <code>Scheduler</code>'s<i>global</i> list.
* </p>
*/
public List getGlobalTriggerListeners() {
return new LinkedList(globalTriggerListeners);
}
/**
* <p>
* Get a Set containing the names of all the <i>non-global</i><code>{@link org.quartz.TriggerListener}</code>
* s registered with the <code>Scheduler</code>.
* </p>
*/
public Set getTriggerListenerNames() {
return Collections.unmodifiableSet(triggerListeners.keySet());
}
/**
* <p>
* Get the <i>non-global</i><code>{@link org.quartz.TriggerListener}</code>
* that has the given name.
* </p>
*/
public TriggerListener getTriggerListener(String name) {
return (TriggerListener) triggerListeners.get(name);
}
/**
* <p>
* Register the given <code>{@link SchedulerListener}</code> with the
* <code>Scheduler</code>.
* </p>
*/
public void addSchedulerListener(SchedulerListener schedulerListener) {
schedulerListeners.add(schedulerListener);
}
/**
* <p>
* Remove the given <code>{@link SchedulerListener}</code> from the
* <code>Scheduler</code>.
* </p>
*
* @return true if the identifed listener was found in the list, and
* removed.
*/
public boolean removeSchedulerListener(SchedulerListener schedulerListener) {
return schedulerListeners.remove(schedulerListener);
}
/**
* <p>
* Get a List containing all of the <code>{@link SchedulerListener}</code>
* s registered with the <code>Scheduler</code>.
* </p>
*/
public List getSchedulerListeners() {
return (List) schedulerListeners.clone();
}
protected void notifyJobStoreJobComplete(SchedulingContext ctxt,
Trigger trigger, JobDetail detail, int instCode)
throws JobPersistenceException {
resources.getJobStore().triggeredJobComplete(ctxt, trigger, detail,
instCode);
}
protected void notifySchedulerThread() {
if (isSignalOnSchedulingChange()) schedThread.signalSchedulingChange();
}
private List buildTriggerListenerList(String[] additionalLstnrs)
throws SchedulerException {
List triggerListeners = getGlobalTriggerListeners();
for (int i = 0; i < additionalLstnrs.length; i++) {
TriggerListener tl = getTriggerListener(additionalLstnrs[i]);
if (tl != null) triggerListeners.add(tl);
else
throw new SchedulerException("TriggerListener '"
+ additionalLstnrs[i] + "' not found.",
SchedulerException.ERR_TRIGGER_LISTENER_NOT_FOUND);
}
return triggerListeners;
}
private List buildJobListenerList(String[] additionalLstnrs)
throws SchedulerException {
List jobListeners = getGlobalJobListeners();
for (int i = 0; i < additionalLstnrs.length; i++) {
JobListener jl = getJobListener(additionalLstnrs[i]);
if (jl != null) jobListeners.add(jl);
else
throw new SchedulerException("JobListener '"
+ additionalLstnrs[i] + "' not found.",
SchedulerException.ERR_JOB_LISTENER_NOT_FOUND);
}
return jobListeners;
}
public boolean notifyTriggerListenersFired(JobExecutionContext jec)
throws SchedulerException {
// build a list of all trigger listeners that are to be notified...
List triggerListeners = buildTriggerListenerList(jec.getTrigger()
.getTriggerListenerNames());
boolean vetoedExecution = false;
// notify all trigger listeners in the list
java.util.Iterator itr = triggerListeners.iterator();
while (itr.hasNext()) {
TriggerListener tl = (TriggerListener) itr.next();
try {
tl.triggerFired(jec.getTrigger(), jec);
if(tl.vetoJobExecution(jec.getTrigger(), jec))
vetoedExecution = true;
} catch (Exception e) {
SchedulerException se = new SchedulerException(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -