@ -159,6 +159,8 @@ public abstract class JobStoreSupport implements JobStore, Constants {
private volatile boolean schedulerRunning = false ;
private volatile boolean shutdown = false ;
private volatile String currentId ;
/ *
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
*
@ -167,6 +169,11 @@ public abstract class JobStoreSupport implements JobStore, Constants {
* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
* /
@Override
public void setCurrentId ( String currentId ) {
this . currentId = currentId ;
}
/ * *
* < p >
* Set the name of the < code > DataSource < / code > that should be used for
@ -854,14 +861,14 @@ public abstract class JobStoreSupport implements JobStore, Constants {
try {
// update inconsistent job states
int rows = getDelegate ( ) . updateTriggerStatesFromOtherStates ( conn ,
STATE_WAITING , STATE_ACQUIRED , STATE_BLOCKED ) ;
STATE_WAITING , STATE_ACQUIRED , STATE_BLOCKED , STATE_ERROR ) ;
rows + = getDelegate ( ) . updateTriggerStatesFromOtherStates ( conn ,
STATE_PAUSED , STATE_PAUSED_BLOCKED , STATE_PAUSED_BLOCKED ) ;
getLog ( ) . info (
"Freed " + rows
+ " triggers from 'acquired' / 'blocked' state." ) ;
+ " triggers from 'acquired' / 'blocked' / 'error' state." ) ;
// clean up misfired jobs
recoverMisfiredJobs ( conn , true ) ;
@ -2780,6 +2787,17 @@ public abstract class JobStoreSupport implements JobStore, Constants {
} ) ;
}
private void mergeKeys ( List < TriggerKey > allKeys , Set < String > allKeyIds , List < TriggerKey > mergeKeys ) {
if ( mergeKeys ! = null ) {
for ( TriggerKey key : mergeKeys ) {
if ( ! allKeyIds . contains ( key . toString ( ) ) ) {
allKeys . add ( key ) ;
allKeyIds . add ( key . toString ( ) ) ;
}
}
}
}
// FUTURE_TODO: this really ought to return something like a FiredTriggerBundle,
// so that the fireInstanceId doesn't have to be on the trigger...
protected List < OperableTrigger > acquireNextTrigger ( Connection conn , long noLaterThan , int maxCount , long timeWindow )
@ -2795,15 +2813,22 @@ public abstract class JobStoreSupport implements JobStore, Constants {
do {
currentLoopCount + + ;
try {
List < TriggerKey > keys = getDelegate ( ) . selectTriggerToAcquire ( conn , noLaterThan + timeWindow , getMisfireTime ( ) , maxCount ) ;
long misfireTime = getMisfireTime ( ) ;
List < TriggerKey > waitingKeys = getDelegate ( ) . selectTriggerToAcquire ( conn , noLaterThan + timeWindow , misfireTime , maxCount ) ;
List < TriggerKey > appointKeys = getDelegate ( ) . selectAppointTriggerToAcquire ( conn , noLaterThan + timeWindow , misfireTime , maxCount , this . currentId ) ;
List < TriggerKey > allKeys = new ArrayList < TriggerKey > ( ) ;
Set < String > keyIds = new HashSet < String > ( ) ;
mergeKeys ( allKeys , keyIds , waitingKeys ) ;
mergeKeys ( allKeys , keyIds , appointKeys ) ;
// No trigger is ready to fire yet.
if ( keys = = null | | keys . size ( ) = = 0 )
if ( keyId s . size ( ) = = 0 )
return acquiredTriggers ;
long batchEnd = noLaterThan ;
for ( TriggerKey triggerKey : k eys) {
for ( TriggerKey triggerKey : allK eys) {
// If our trigger is no longer available, try a new one.
OperableTrigger nextTrigger = retrieveTrigger ( conn , triggerKey ) ;
if ( nextTrigger = = null ) {