下面列出了怎么用org.quartz.JobPersistenceException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* <p>
* Pause all of the <code>{@link org.quartz.Trigger}s</code> in the
* given group.
* </p>
*
* @see #resumeTriggerGroup(Connection, SchedulingContext, String)
*/
public void pauseTriggerGroup(Connection conn, SchedulingContext ctxt,
String groupName) throws JobPersistenceException {
try {
getDelegate().updateTriggerGroupStateFromOtherStates(
conn, groupName, STATE_PAUSED, STATE_ACQUIRED,
STATE_WAITING, STATE_WAITING);
getDelegate().updateTriggerGroupStateFromOtherState(
conn, groupName, STATE_PAUSED_BLOCKED, STATE_BLOCKED);
if (!getDelegate().isTriggerGroupPaused(conn, groupName)) {
getDelegate().insertPausedTriggerGroup(conn, groupName);
}
} catch (SQLException e) {
throw new JobPersistenceException("Couldn't pause trigger group '"
+ groupName + "': " + e.getMessage(), e);
}
}
protected Trigger retrieveTrigger(Connection conn, String triggerName, String groupName)
throws JobPersistenceException {
try {
Trigger trigger = getDelegate().selectTrigger(conn, triggerName,
groupName);
if (trigger == null) {
return null;
}
// In case Trigger was BLOB, clear out any listeners that might
// have been serialized.
trigger.clearAllTriggerListeners();
String[] listeners = getDelegate().selectTriggerListeners(conn,
triggerName, groupName);
for (int i = 0; i < listeners.length; ++i) {
trigger.addTriggerListener(listeners[i]);
}
return trigger;
} catch (Exception e) {
throw new JobPersistenceException("Couldn't retrieve trigger: "
+ e.getMessage(), e);
}
}
/**
* <p>
* Resume (un-pause) all of the <code>{@link org.quartz.Job}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>
*
* @see #pauseJobGroup(SchedulingContext, String)
*/
public void resumeJobGroup(final SchedulingContext ctxt, final String groupName)
throws JobPersistenceException {
executeInLock(
LOCK_TRIGGER_ACCESS,
new VoidTransactionCallback() {
public void execute(Connection conn) throws JobPersistenceException {
String[] jobNames = getJobNames(conn, ctxt, groupName);
for (int i = 0; i < jobNames.length; i++) {
Trigger[] triggers = getTriggersForJob(conn, ctxt, jobNames[i], groupName);
for (int j = 0; j < triggers.length; j++) {
resumeTrigger(conn, ctxt, triggers[j].getName(), triggers[j].getGroup());
}
}
}
});
}
private void doUpdateOfMisfiredTrigger(Connection conn, SchedulingContext ctxt, Trigger trig, boolean forceState, String newStateIfNotComplete, boolean recovering) throws JobPersistenceException {
Calendar cal = null;
if (trig.getCalendarName() != null) {
cal = retrieveCalendar(conn, ctxt, trig.getCalendarName());
}
schedSignaler.notifyTriggerListenersMisfired(trig);
trig.updateAfterMisfire(cal);
if (trig.getNextFireTime() == null) {
storeTrigger(conn, ctxt, trig,
null, true, STATE_COMPLETE, forceState, recovering);
} else {
storeTrigger(conn, ctxt, trig, null, true, newStateIfNotComplete,
forceState, false);
}
}
/**
* <p>
* Get the current state of the identified <code>{@link Trigger}</code>.
* </p>
*
* @see Trigger.TriggerState
*/
@Override
public Trigger.TriggerState getTriggerState(org.quartz.TriggerKey key) throws JobPersistenceException {
TriggerWrapper tw;
lock();
try {
tw = triggerFacade.get(key);
} finally {
unlock();
}
if (tw == null) { return Trigger.TriggerState.NONE; }
if (tw.getState() == TriggerState.COMPLETE) { return Trigger.TriggerState.COMPLETE; }
if (tw.getState() == TriggerState.PAUSED) { return Trigger.TriggerState.PAUSED; }
if (tw.getState() == TriggerState.PAUSED_BLOCKED) { return Trigger.TriggerState.PAUSED; }
if (tw.getState() == TriggerState.BLOCKED) { return Trigger.TriggerState.BLOCKED; }
if (tw.getState() == TriggerState.ERROR) { return Trigger.TriggerState.ERROR; }
return Trigger.TriggerState.NORMAL;
}
public boolean removeTriggers(final List<TriggerKey> triggerKeys)
throws JobPersistenceException {
return (Boolean) executeInLock(
LOCK_TRIGGER_ACCESS,
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
boolean allFound = true;
// FUTURE_TODO: make this more efficient with a true bulk operation...
for (TriggerKey triggerKey : triggerKeys)
allFound = removeTrigger(conn, triggerKey) && allFound;
return allFound ? Boolean.TRUE : Boolean.FALSE;
}
});
}
private boolean releaseIfScheduleChangedSignificantly(Trigger trigger, long triggerTime) {
if(isCandidateNewTimeEarlierWithinReason(triggerTime, true)) {
// above call does a clearSignaledSchedulingChange()
try {
qsRsrcs.getJobStore().releaseAcquiredTrigger(
ctxt, trigger);
} catch (JobPersistenceException jpe) {
qs.notifySchedulerListenersError(
"An error occured while releasing trigger '"
+ trigger.getFullName() + "'",
jpe);
// db connection must have failed... keep
// retrying until it's up...
releaseTriggerRetryLoop(trigger);
} catch (RuntimeException e) {
getLog().error(
"releaseTriggerRetryLoop: RuntimeException "
+e.getMessage(), e);
// db connection must have failed... keep
// retrying until it's up...
releaseTriggerRetryLoop(trigger);
}
return true;
}
return false;
}
@Override
public List<OperableTrigger> acquireNextTriggers(long noLaterThan, int maxCount, long timeWindow)
throws JobPersistenceException {
try {
return realJobStore.acquireNextTriggers(noLaterThan, maxCount, timeWindow);
} catch (RejoinException e) {
throw new JobPersistenceException("Trigger acquisition failed due to client rejoin", e);
}
}
@Override
public List<String> getCalendarNames() throws JobPersistenceException {
try {
return realJobStore.getCalendarNames();
} catch (RejoinException e) {
throw new JobPersistenceException("Calendar name retrieval failed due to client rejoin", e);
}
}
/**
* Determines if a Trigger for the given job should be blocked.
* State can only transition to STATE_PAUSED_BLOCKED/BLOCKED from
* PAUSED/STATE_WAITING respectively.
*
* @return STATE_PAUSED_BLOCKED, BLOCKED, or the currentState.
*/
protected String checkBlockedState(
Connection conn, JobKey jobKey, String currentState)
throws JobPersistenceException {
// State can only transition to BLOCKED from PAUSED or WAITING.
if ((!currentState.equals(STATE_WAITING)) &&
(!currentState.equals(STATE_PAUSED))) {
return currentState;
}
try {
List<FiredTriggerRecord> lst = getDelegate().selectFiredTriggerRecordsByJob(conn,
jobKey.getName(), jobKey.getGroup());
if (lst.size() > 0) {
FiredTriggerRecord rec = lst.get(0);
if (rec.isJobDisallowsConcurrentExecution()) { // OLD_TODO: worry about failed/recovering/volatile job states?
return (STATE_PAUSED.equals(currentState)) ? STATE_PAUSED_BLOCKED : STATE_BLOCKED;
}
}
return currentState;
} catch (SQLException e) {
throw new JobPersistenceException(
"Couldn't determine if trigger should be in a blocked state '"
+ jobKey + "': "
+ e.getMessage(), e);
}
}
protected List<String> getTriggerGroupNames(Connection conn) throws JobPersistenceException {
List<String> groupNames;
try {
groupNames = getDelegate().selectTriggerGroups(conn);
} catch (SQLException e) {
throw new JobPersistenceException(
"Couldn't obtain trigger groups: " + e.getMessage(), e);
}
return groupNames;
}
/**
* <p>
* Get the number of <code>{@link org.quartz.Calendar}</code> s that are
* stored in the <code>JobsStore</code>.
* </p>
*/
public int getNumberOfCalendars(final SchedulingContext ctxt)
throws JobPersistenceException {
return ((Integer)executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
return new Integer(getNumberOfCalendars(conn, ctxt));
}
})).intValue();
}
@Override
public Set<String> getPausedTriggerGroups() throws JobPersistenceException {
try {
return realJobStore.getPausedTriggerGroups();
} catch (RejoinException e) {
throw new JobPersistenceException("Paused trigger group retrieval failed due to client rejoin", e);
}
}
@Override
public List<String> getTriggerGroupNames() throws JobPersistenceException {
try {
return realJobStore.getTriggerGroupNames();
} catch (RejoinException e) {
throw new JobPersistenceException("Trigger group retrieval failed due to client rejoin", e);
}
}
/**
* <p>
* Pause all of the <code>{@link org.quartz.Trigger}s</code> matching the
* given groupMatcher.
* </p>
*
* @see #resumeTriggerGroup(java.sql.Connection, org.quartz.impl.matchers.GroupMatcher)
*/
@SuppressWarnings("unchecked")
public Set<String> pauseTriggers(final GroupMatcher<TriggerKey> matcher)
throws JobPersistenceException {
return (Set<String>) executeInLock(
LOCK_TRIGGER_ACCESS,
new TransactionCallback() {
public Set<String> execute(Connection conn) throws JobPersistenceException {
return pauseTriggerGroup(conn, matcher);
}
});
}
@Override
public Collection<String> pauseJobs(GroupMatcher<JobKey> matcher) throws JobPersistenceException {
try {
return realJobStore.pauseJobs(matcher);
} catch (RejoinException e) {
throw new JobPersistenceException("Pausing jobs failed due to client rejoin", e);
}
}
/**
* <p>
* Get all of the Triggers that are associated to the given Job.
* </p>
*
* <p>
* If there are no matches, a zero-length array should be returned.
* </p>
*/
@SuppressWarnings("unchecked")
public List<OperableTrigger> getTriggersForJob(final JobKey jobKey) throws JobPersistenceException {
return (List<OperableTrigger>)executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
return getTriggersForJob(conn, jobKey);
}
});
}
/**
* <p>
* Retrieve the given <code>{@link org.quartz.Trigger}</code>.
* </p>
*
* @return The desired <code>Trigger</code>, or null if there is no
* match.
*/
public OperableTrigger retrieveTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
return (OperableTrigger)executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
return retrieveTrigger(conn, triggerKey);
}
});
}
/**
* @see org.quartz.spi.JobStore#getPausedTriggerGroups()
*/
@Override
public Set<String> getPausedTriggerGroups() throws JobPersistenceException {
lock();
try {
return new HashSet<String>(triggerFacade.allPausedTriggersGroupNames());
} finally {
unlock();
}
}
@Override
public boolean removeTrigger(TriggerKey triggerKey) throws JobPersistenceException {
try {
return realJobStore.removeTrigger(triggerKey);
} catch (RejoinException e) {
throw new JobPersistenceException("Removing trigger failed due to client rejoin", e);
}
}
protected boolean calendarExists(Connection conn, String calName)
throws JobPersistenceException {
try {
return getDelegate().calendarExists(conn, calName);
} catch (SQLException e) {
throw new JobPersistenceException(
"Couldn't determine calendar existence (" + calName + "): "
+ e.getMessage(), e);
}
}
protected List<OperableTrigger> getTriggersForJob(Connection conn,
JobKey key)
throws JobPersistenceException {
List<OperableTrigger> list;
try {
list = getDelegate()
.selectTriggersForJob(conn, key);
} catch (Exception e) {
throw new JobPersistenceException(
"Couldn't obtain triggers for job: " + e.getMessage(), e);
}
return list;
}
protected String[] getJobGroupNames(Connection conn, SchedulingContext ctxt)
throws JobPersistenceException {
String[] groupNames = null;
try {
groupNames = getDelegate().selectJobGroups(conn);
} catch (SQLException e) {
throw new JobPersistenceException("Couldn't obtain job groups: "
+ e.getMessage(), e);
}
return groupNames;
}
@Override
public Collection<String> resumeTriggers(GroupMatcher<TriggerKey> matcher) throws JobPersistenceException {
try {
return realJobStore.resumeTriggers(matcher);
} catch (RejoinException e) {
throw new JobPersistenceException("Resuming triggers failed due to client rejoin", e);
}
}
@Override
public Calendar retrieveCalendar(String calName) throws JobPersistenceException {
try {
return realJobStore.retrieveCalendar(calName);
} catch (RejoinException e) {
throw new JobPersistenceException("Calendar retrieval failed due to client rejoin", e);
}
}
@Override
public JobDetail retrieveJob(JobKey jobKey) throws JobPersistenceException {
try {
return realJobStore.retrieveJob(jobKey);
} catch (RejoinException e) {
throw new JobPersistenceException("Job retrieval failed due to client rejoin", e);
}
}
@Override
public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers)
throws ObjectAlreadyExistsException, JobPersistenceException {
try {
realJobStore.storeCalendar(name, calendar, replaceExisting, updateTriggers);
} catch (RejoinException e) {
throw new JobPersistenceException("Storing calendar failed due to client rejoin", e);
}
}
protected String[] getTriggerNames(Connection conn, SchedulingContext ctxt,
String groupName) throws JobPersistenceException {
String[] trigNames = null;
try {
trigNames = getDelegate().selectTriggersInGroup(conn, groupName);
} catch (SQLException e) {
throw new JobPersistenceException("Couldn't obtain trigger names: "
+ e.getMessage(), e);
}
return trigNames;
}
@SuppressWarnings("unchecked")
public Set<String> getPausedTriggerGroups()
throws JobPersistenceException {
return (Set<String>)executeWithoutLock( // no locks necessary for read...
new TransactionCallback() {
public Object execute(Connection conn) throws JobPersistenceException {
return getPausedTriggerGroups(conn);
}
});
}
/**
* <p>
* Pause all of the <code>{@link org.quartz.Trigger}s</code> matching the
* given groupMatcher.
* </p>
*
* @see #resumeTriggerGroup(java.sql.Connection, org.quartz.impl.matchers.GroupMatcher)
*/
public Set<String> pauseTriggerGroup(Connection conn,
GroupMatcher<TriggerKey> matcher) throws JobPersistenceException {
try {
getDelegate().updateTriggerGroupStateFromOtherStates(
conn, matcher, STATE_PAUSED, STATE_ACQUIRED,
STATE_WAITING, STATE_WAITING);
getDelegate().updateTriggerGroupStateFromOtherState(
conn, matcher, STATE_PAUSED_BLOCKED, STATE_BLOCKED);
List<String> groups = getDelegate().selectTriggerGroups(conn, matcher);
// make sure to account for an exact group match for a group that doesn't yet exist
StringMatcher.StringOperatorName operator = matcher.getCompareWithOperator();
if (operator.equals(StringOperatorName.EQUALS) && !groups.contains(matcher.getCompareToValue())) {
groups.add(matcher.getCompareToValue());
}
for (String group : groups) {
if (!getDelegate().isTriggerGroupPaused(conn, group)) {
getDelegate().insertPausedTriggerGroup(conn, group);
}
}
return new HashSet<String>(groups);
} catch (SQLException e) {
throw new JobPersistenceException("Couldn't pause trigger group '"
+ matcher + "': " + e.getMessage(), e);
}
}