use of org.alfresco.repo.lock.LockAcquisitionException in project alfresco-repository by Alfresco.
the class LockingJob method execute.
@Override
public void execute(final JobExecutionContext jobexecutioncontext) throws JobExecutionException {
final JobDataMap dataMap = jobexecutioncontext.getJobDetail().getJobDataMap();
final HBBaseDataCollector collector = (HBBaseDataCollector) dataMap.get(COLLECTOR_KEY);
final HBDataSenderService hbDataSenderService = (HBDataSenderService) dataMap.get(DATA_SENDER_SERVICE_KEY);
final JobLockService jobLockService = (JobLockService) dataMap.get(JOB_LOCK_SERVICE_KEY);
ParameterCheck.mandatory(COLLECTOR_KEY, collector);
ParameterCheck.mandatory(DATA_SENDER_SERVICE_KEY, hbDataSenderService);
ParameterCheck.mandatory(JOB_LOCK_SERVICE_KEY, jobLockService);
QName lockQname = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, collector.getCollectorId());
LockCallback lockCallback = new LockCallback(lockQname);
try {
// Get lock
String lockToken = jobLockService.getLock(lockQname, LOCK_TTL);
// Register the refresh callback which will keep the lock alive.
// The lock will not be released manually,
// instead the job lock service will check the callback (running) flag every LOCK_TTL/2 ms from lock acquisition
// and release the lock when the flag is set to false.
jobLockService.refreshLock(lockToken, lockQname, LOCK_TTL, lockCallback);
if (logger.isDebugEnabled()) {
logger.debug("Lock acquired: " + lockQname + ": " + lockToken);
}
// Collect data and pass it to the data sender service
collectAndSendDataLocked(collector, hbDataSenderService);
} catch (LockAcquisitionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping collect and send data (could not get lock): " + e.getMessage());
}
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Finished collector job. ID: " + collector.getCollectorId());
}
lockCallback.running.set(false);
}
}
Aggregations