*
* Roller tasks should put their logic in the runTask() method.
*/
public final void run() {
ThreadManager mgr = null;
try {
mgr = RollerFactory.getRoller().getThreadManager();
} catch (Exception ex) {
log.fatal("Unable to obtain ThreadManager", ex);
return;
}
boolean lockAcquired = false;
try {
if(!mgr.isLocked(this)) {
log.debug("Attempting to acquire lock");
lockAcquired = mgr.acquireLock(this);
// now if we have a lock then run the task
if(lockAcquired) {
log.debug("Lock acquired, running task");
this.runTask();
} else {
log.debug("Lock NOT acquired, cannot continue");
// when we don't have a lock we can't continue, so bail
return;
}
} else {
log.debug("Task already locked, nothing to do");
}
} catch (Exception ex) {
log.error("Unexpected exception running task", ex);
} finally {
if(lockAcquired) {
log.debug("Attempting to release lock");
boolean lockReleased = mgr.releaseLock(this);
if(lockReleased) {
log.debug("Lock released, time to sleep");
} else {
log.debug("Lock NOT released, some kind of problem");