public Boolean execute(Environment environment) throws Exception {
if (log.isDebugEnabled()) log.debug("executing " + this);
if (environment==null) {
throw new JbpmException("environment is null");
}
if (signalName!=null) {
if (log.isDebugEnabled()) log.debug("feeding timer signal "+signalName+" into "+execution);
execution.signal(signalName);
}
if (eventName!=null) {
ObservableElement eventSource = execution.getActivity();
if (log.isDebugEnabled()) log.debug("firing event "+signalName+" into "+eventSource);
execution.fire(eventName, eventSource);
}
boolean deleteThisJob = true;
// if there is no repeat on this timer
if (repeat==null) {
// delete the job
if (log.isDebugEnabled()) log.debug("deleting " + this);
DbSession dbSession = environment.get(DbSession.class);
if (dbSession==null) {
throw new JbpmException("no "+DbSession.class.getName()+" in environment");
}
dbSession.delete(this);
} else { // there is a repeat on this timer
deleteThisJob = false;
// suppose that it took the timer runner thread a very long time to execute the timers
// then the repeat action duedate could already have passed
do {
setDueDateDescription(repeat);
} while (dueDate.getTime() <= Clock.getCurrentTime().getTime());
if (log.isDebugEnabled()) log.debug("rescheduled "+this+" for "+formatDueDate(dueDate));
// release the lock on the timer
release();
// notify the jobExecutor at the end of the transaction
JobExecutor jobExecutor = environment.get(JobExecutor.class);
if (jobExecutor!=null) {
Transaction transaction = environment.get(Transaction.class);
if (transaction==null) {
throw new JbpmException("no transaction in environment");
}
JobAddedNotification jobNotificator = new JobAddedNotification(jobExecutor);
transaction.registerSynchronization(jobNotificator);
}
}