try {
for (OperableTrigger trigger : triggersFired) {
TriggerWrapper tw = triggerFacade.get(trigger.getKey());
// was the trigger deleted since being acquired?
if (tw == null) {
results.add(new TriggerFiredResult((TriggerFiredBundle) null));
continue;
}
// was the trigger completed, paused, blocked, etc. since being acquired?
if (tw.getState() != TriggerState.ACQUIRED) {
results.add(new TriggerFiredResult((TriggerFiredBundle) null));
continue;
}
Calendar cal = null;
if (tw.getCalendarName() != null) {
cal = retrieveCalendar(tw.getCalendarName());
if (cal == null) {
results.add(new TriggerFiredResult((TriggerFiredBundle) null));
continue;
}
}
Date prevFireTime = trigger.getPreviousFireTime();
// in case trigger was replaced between acquiring and firering
timeTriggers.remove(tw);
// call triggered on our copy, and the scheduler's copy
tw.triggered(cal, triggerFacade);
trigger.triggered(cal); // calendar is already clone()'d so it is okay to pass out to trigger
// tw.state = EXECUTING;
tw.setState(TriggerState.WAITING, terracottaClientId, triggerFacade);
TriggerFiredBundle bndle = new TriggerFiredBundle(retrieveJob(trigger.getJobKey()), trigger, cal, false,
new Date(), trigger.getPreviousFireTime(), prevFireTime,
trigger.getNextFireTime());
String fireInstanceId = trigger.getFireInstanceId();
FiredTrigger prev = triggerFacade.getFiredTrigger(fireInstanceId);
triggerFacade.putFiredTrigger(fireInstanceId, new FiredTrigger(terracottaClientId, tw.getKey(), trigger.getPreviousFireTime().getTime()));
getLog().trace("Tracking " + trigger + " has fired on " + fireInstanceId);
if (prev != null) {
// this shouldn't happen
throw new AssertionError("duplicate fireInstanceId detected (" + fireInstanceId + ") for " + trigger
+ ", previous is " + prev);
}
JobDetail job = bndle.getJobDetail();
if (job.isConcurrentExectionDisallowed()) {
List<TriggerWrapper> trigs = triggerFacade.getTriggerWrappersForJob(job.getKey());
for (TriggerWrapper ttw : trigs) {
if (ttw.getKey().equals(tw.getKey())) {
continue;
}
if (ttw.getState() == TriggerState.WAITING) {
ttw.setState(TriggerState.BLOCKED, terracottaClientId, triggerFacade);
}
if (ttw.getState() == TriggerState.PAUSED) {
ttw.setState(TriggerState.PAUSED_BLOCKED, terracottaClientId, triggerFacade);
}
timeTriggers.remove(ttw);
if (triggerRemovedFromCandidateFiringListHandler != null) {
triggerRemovedFromCandidateFiringListHandler.removeCandidateTrigger(ttw);
}
}
jobFacade.addBlockedJob(job.getKey());
} else if (tw.getNextFireTime() != null) {
timeTriggers.add(tw);
}
results.add(new TriggerFiredResult(bndle));
}
return results;
} finally {
try {
unlock();