*/
public boolean acquireLock(RollerTask task) {
boolean lockAcquired = false;
TaskLockData taskLock = null;
try {
taskLock = this.getTaskLockByName(task.getName());
// null here just means hasn't been initialized yet
if(taskLock == null) {
taskLock = new TaskLockData();
taskLock.setName(task.getName());
taskLock.setLocked(false);
}
} catch (RollerException ex) {
log.warn("Error getting TaskLockData", ex);
return false;
}
Date now = new Date();
Date nextRun = taskLock.getNextRun(task.getInterval());
if( !taskLock.isLocked() && (nextRun == null || now.after(nextRun))) {
// set appropriate values for TaskLock and save it
taskLock.setLocked(true);
taskLock.setTimeAquired(now);
taskLock.setTimeLeased(task.getLeaseTime());
taskLock.setLastRun(now);
try {
// save it *and* flush
this.saveTaskLock(taskLock);
RollerFactory.getRoller().flush();