use of org.alfresco.repo.lock.JobLockService 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);
}
}
use of org.alfresco.repo.lock.JobLockService in project alfresco-repository by Alfresco.
the class AbstractScheduledLockedJob method executeInternal.
@Override
protected final synchronized void executeInternal(final JobExecutionContext jobContext) throws JobExecutionException {
if (locker == null) {
JobLockService jobLockServiceBean = (JobLockService) jobContext.getJobDetail().getJobDataMap().get("jobLockService");
if (jobLockServiceBean == null)
throw new JobExecutionException("Missing setting for bean jobLockService");
String name = (String) jobContext.getJobDetail().getJobDataMap().get("name");
String jobName = name == null ? this.getClass().getSimpleName() : name;
locker = new ScheduledJobLockExecuter(jobLockServiceBean, jobName, this);
}
locker.execute(jobContext);
}
use of org.alfresco.repo.lock.JobLockService in project alfresco-repository by Alfresco.
the class AbstractFeedCleanerTest method setUp.
@Before
public void setUp() throws Exception {
ctx = ApplicationContextHelper.getApplicationContext();
JobLockService jobLockService = (JobLockService) ctx.getBean("JobLockService");
PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
NodeService nodeService = (NodeService) ctx.getBean("NodeService");
siteService = (SiteService) ctx.getBean("SiteService");
personService = (PersonService) ctx.getBean("PersonService");
feedDAO = (ActivityFeedDAO) ctx.getBean("feedDAO");
transactionHelper = (RetryingTransactionHelper) ctx.getBean("retryingTransactionHelper");
nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
// Let's shut down the scheduler so that we aren't competing with the scheduled versions of jobs (ie. feed cleaner)
Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");
scheduler.shutdown();
tearDown();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
for (int i = 1; i <= 7; i++) {
siteService.createSite("myPreset", "testSite" + i, null, null, SiteVisibility.PUBLIC);
}
AuthenticationUtil.setRunAsUserSystem();
// construct the test cleaner
cleaner = new FeedCleaner();
cleaner.setFeedDAO(feedDAO);
cleaner.setPolicyComponent(policyComponent);
cleaner.setJobLockService(jobLockService);
cleaner.setNodeService(nodeService);
}
Aggregations