📄 ramjobstore.java
字号:
* <p>
* If there are no matches, a zero-length array should be returned.
* </p>
*/
public Trigger[] getTriggersForJob(SchedulingContext ctxt, String jobName,
String groupName) {
ArrayList trigList = new ArrayList();
String jobKey = JobWrapper.getJobNameKey(jobName, groupName);
synchronized (triggerLock) {
for (int i = 0; i < triggers.size(); i++) {
TriggerWrapper tw = (TriggerWrapper) triggers.get(i);
if (tw.jobKey.equals(jobKey)) {
trigList.add(tw.trigger.clone());
}
}
}
return (Trigger[]) trigList.toArray(new Trigger[trigList.size()]);
}
protected ArrayList getTriggerWrappersForJob(String jobName, String groupName) {
ArrayList trigList = new ArrayList();
String jobKey = JobWrapper.getJobNameKey(jobName, groupName);
synchronized (triggerLock) {
for (int i = 0; i < triggers.size(); i++) {
TriggerWrapper tw = (TriggerWrapper) triggers.get(i);
if (tw.jobKey.equals(jobKey)) {
trigList.add(tw);
}
}
}
return trigList;
}
protected ArrayList getTriggerWrappersForCalendar(String calName) {
ArrayList trigList = new ArrayList();
synchronized (triggerLock) {
for (int i = 0; i < triggers.size(); i++) {
TriggerWrapper tw = (TriggerWrapper) triggers.get(i);
String tcalName = tw.getTrigger().getCalendarName();
if (tcalName != null && tcalName.equals(calName)) {
trigList.add(tw);
}
}
}
return trigList;
}
/**
* <p>
* Pause the <code>{@link Trigger}</code> with the given name.
* </p>
*
*/
public void pauseTrigger(SchedulingContext ctxt, String triggerName,
String groupName) {
TriggerWrapper tw = (TriggerWrapper) triggersByFQN.get(TriggerWrapper
.getTriggerNameKey(triggerName, groupName));
// does the trigger exist?
if (tw == null || tw.trigger == null) {
return;
}
// if the trigger is "complete" pausing it does not make sense...
if (tw.state == TriggerWrapper.STATE_COMPLETE) {
return;
}
synchronized (triggerLock) {
if(tw.state == TriggerWrapper.STATE_BLOCKED) {
tw.state = TriggerWrapper.STATE_PAUSED_BLOCKED;
} else {
tw.state = TriggerWrapper.STATE_PAUSED;
}
timeTriggers.remove(tw);
}
}
/**
* <p>
* Pause all of the <code>{@link Trigger}s</code> in the given group.
* </p>
*
* <p>
* The JobStore should "remember" that the group is paused, and impose the
* pause on any new triggers that are added to the group while the group is
* paused.
* </p>
*
*/
public void pauseTriggerGroup(SchedulingContext ctxt, String groupName) {
synchronized (triggerLock) {
if (pausedTriggerGroups.contains(groupName)) {
return;
}
pausedTriggerGroups.add(groupName);
String[] names = getTriggerNames(ctxt, groupName);
for (int i = 0; i < names.length; i++) {
pauseTrigger(ctxt, names[i], groupName);
}
}
}
/**
* <p>
* Pause the <code>{@link org.quartz.JobDetail}</code> with the given
* name - by pausing all of its current <code>Trigger</code>s.
* </p>
*
*/
public void pauseJob(SchedulingContext ctxt, String jobName,
String groupName) {
synchronized (triggerLock) {
Trigger[] triggers = getTriggersForJob(ctxt, jobName, groupName);
for (int j = 0; j < triggers.length; j++) {
pauseTrigger(ctxt, triggers[j].getName(), triggers[j].getGroup());
}
}
}
/**
* <p>
* Pause all of the <code>{@link org.quartz.JobDetail}s</code> in the
* given group - by pausing all of their <code>Trigger</code>s.
* </p>
*
*
* <p>
* The JobStore should "remember" that the group is paused, and impose the
* pause on any new jobs that are added to the group while the group is
* paused.
* </p>
*/
public void pauseJobGroup(SchedulingContext ctxt, String groupName) {
synchronized (triggerLock) {
if (!pausedJobGroups.contains(groupName)) {
pausedJobGroups.add(groupName);
}
String[] jobNames = getJobNames(ctxt, groupName);
for (int i = 0; i < jobNames.length; i++) {
Trigger[] triggers = getTriggersForJob(ctxt, jobNames[i],
groupName);
for (int j = 0; j < triggers.length; j++) {
pauseTrigger(ctxt, triggers[j].getName(),
triggers[j].getGroup());
}
}
}
}
/**
* <p>
* Resume (un-pause) the <code>{@link Trigger}</code> with the given
* name.
* </p>
*
* <p>
* If the <code>Trigger</code> missed one or more fire-times, then the
* <code>Trigger</code>'s misfire instruction will be applied.
* </p>
*
*/
public void resumeTrigger(SchedulingContext ctxt, String triggerName,
String groupName) {
TriggerWrapper tw = (TriggerWrapper) triggersByFQN.get(TriggerWrapper
.getTriggerNameKey(triggerName, groupName));
// does the trigger exist?
if (tw == null || tw.trigger == null) {
return;
}
Trigger trig = tw.getTrigger();
// if the trigger is not paused resuming it does not make sense...
if (tw.state != TriggerWrapper.STATE_PAUSED &&
tw.state != TriggerWrapper.STATE_PAUSED_BLOCKED) {
return;
}
synchronized (triggerLock) {
if(blockedJobs.contains( JobWrapper.getJobNameKey(trig.getJobName(), trig.getJobGroup()) )) {
tw.state = TriggerWrapper.STATE_BLOCKED;
} else {
tw.state = TriggerWrapper.STATE_WAITING;
}
applyMisfire(tw);
if (tw.state == TriggerWrapper.STATE_WAITING) {
timeTriggers.add(tw);
}
}
}
/**
* <p>
* Resume (un-pause) all of the <code>{@link Trigger}s</code> in the
* given group.
* </p>
*
* <p>
* If any <code>Trigger</code> missed one or more fire-times, then the
* <code>Trigger</code>'s misfire instruction will be applied.
* </p>
*
*/
public void resumeTriggerGroup(SchedulingContext ctxt, String groupName) {
synchronized (triggerLock) {
String[] names = getTriggerNames(ctxt, groupName);
for (int i = 0; i < names.length; i++) {
String key = TriggerWrapper.getTriggerNameKey(names[i], groupName);
if(triggersByFQN.get(key) != null) {
String jobGroup = ((TriggerWrapper) triggersByFQN.get(key)).getTrigger().getJobGroup();
if(pausedJobGroups.contains(jobGroup)) {
continue;
}
}
resumeTrigger(ctxt, names[i], groupName);
}
pausedTriggerGroups.remove(groupName);
}
}
/**
* <p>
* Resume (un-pause) the <code>{@link org.quartz.JobDetail}</code> with
* the given name.
* </p>
*
* <p>
* If any of the <code>Job</code>'s<code>Trigger</code> s missed one
* or more fire-times, then the <code>Trigger</code>'s misfire
* instruction will be applied.
* </p>
*
*/
public void resumeJob(SchedulingContext ctxt, String jobName,
String groupName) {
synchronized (triggerLock) {
Trigger[] triggers = getTriggersForJob(ctxt, jobName, groupName);
for (int j = 0; j < triggers.length; j++) {
resumeTrigger(ctxt, triggers[j].getName(), triggers[j].getGroup());
}
}
}
/**
* <p>
* Resume (un-pause) all of the <code>{@link org.quartz.JobDetail}s</code>
* in the given group.
* </p>
*
* <p>
* If any of the <code>Job</code> s had <code>Trigger</code> s that
* missed one or more fire-times, then the <code>Trigger</code>'s
* misfire instruction will be applied.
* </p>
*
*/
public void resumeJobGroup(SchedulingContext ctxt, String groupName) {
synchronized (triggerLock) {
String[] jobNames = getJobNames(ctxt, groupName);
if(pausedJobGroups.contains(groupName)) {
pausedJobGroups.remove(groupName);
}
for (int i = 0; i < jobNames.length; i++) {
Trigger[] triggers = getTriggersForJob(ctxt, jobNames[i],
groupName);
for (int j = 0; j < triggers.length; j++) {
resumeTrigger(ctxt, triggers[j].getName(),
triggers[j].getGroup());
}
}
}
}
/**
* <p>
* Pause all triggers - equivalent of calling <code>pauseTriggerGroup(group)</code>
* on every group.
* </p>
*
* <p>
* When <code>resumeAll()</code> is called (to un-pause), trigger misfire
* instructions WILL be applied.
* </p>
*
* @see #resumeAll(SchedulingContext)
* @see #pauseTriggerGroup(SchedulingContext, String)
*/
public void pauseAll(SchedulingContext ctxt) {
synchronized (triggerLock) {
String[] names = getTriggerGroupNames(ctxt);
for (int i = 0; i < names.length; i++) {
pauseTriggerGroup(ctxt, names[i]);
}
}
}
/**
* <p>
* Resume (un-pause) all triggers - equivalent of calling <code>resumeTriggerGroup(group)</code>
* on every group.
* </p>
*
* <p>
* If any <code>Trigger</code> missed one or more fire-times, then the
* <code>Trigger</code>'s misfire instruction will be applied.
* </p>
*
* @see #pauseAll(SchedulingContext)
*/
public void resumeAll(SchedulingContext ctxt) {
synchronized (triggerLock) {
pausedJobGroups.clear();
String[] names = getTriggerGroupNames(ctxt);
for (int i = 0; i < names.length; i++) {
resumeTriggerGroup(ctxt, names[i]);
}
}
}
protected boolean applyMisfire(TriggerWrapper tw) {
long misfireTime = System.currentTimeMillis();
if (getMisfireThreshold() > 0) {
misfireTime -= getMisfireThreshold();
}
Date tnft = tw.trigger.getNextFireTime();
if (tnft == null || tnft.getTime() > misfireTime) {
return false;
}
Calendar cal = null;
if (tw.trigger.getCalendarName() != null) {
cal = retrieveCalendar(null, tw.trigger.getCalendarName());
}
signaler.notifyTriggerListenersMisfired((Trigger)tw.trigger.clone());
tw.trigger.updateAfterMisfire(cal);
if (tw.trigger.getNextFireTime() == null) {
tw.state = TriggerWrapper.STATE_COMPLETE;
signaler.notifySchedulerListenersFinalized(tw.trigger);
synchronized (triggerLock) {
timeTriggers.remove(tw);
}
} else if (tnft.equals(tw.trigger.getNextFireTime())) {
return false;
}
return true;
}
private static long ftrCtr = System.currentTimeMillis();
protected synchronized String getFiredTriggerRecordId() {
return String.valueOf(ftrCtr++);
}
/**
* <p>
* Get a handle to the next trigger to be fired, and mark it as 'reserved'
* by the calling scheduler.
* </p>
*
* @see #releaseAcquiredTrigger(SchedulingContext, Trigger)
*/
public Trigger acquireNextTrigger(SchedulingContext ctxt, long noLaterThan) {
TriggerWrapper tw = null;
synchronized (triggerLock) {
while (tw == null) {
try {
tw = (TriggerWrapper) timeTriggers.first();
} catch (java.util.NoSuchElementException nsee) {
return null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -