use of org.alfresco.repo.lock.LockAcquisitionException in project alfresco-repository by Alfresco.
the class PostLookup method execute.
public void execute() throws JobExecutionException {
checkProperties();
// Avoid running when in read-only mode
if (!transactionService.getAllowWrite()) {
if (logger.isTraceEnabled()) {
logger.trace("Post lookup not running due to read-only server");
}
return;
}
long start = System.currentTimeMillis();
String lockToken = null;
LockCallback lockCallback = new LockCallback();
try {
if (jobLockService != null) {
lockToken = acquireLock(lockCallback);
}
ActivityPostEntity params = new ActivityPostEntity();
params.setStatus(ActivityPostEntity.STATUS.PENDING.toString());
if (logger.isDebugEnabled()) {
logger.debug("Selecting activity posts with status: " + ActivityPostEntity.STATUS.PENDING.toString());
}
// get all pending post (for this job run)
final List<ActivityPostEntity> activityPosts = postDAO.selectPosts(params, maxItemsPerCycle);
if (activityPosts.size() > 0) {
if (logger.isDebugEnabled()) {
logger.debug("Update: " + activityPosts.size() + " activity post" + (activityPosts.size() == 1 ? "s" : ""));
}
// execute in READ txn
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
// lookup any additional data
lookupPosts(activityPosts);
return null;
}
}, true);
// execute in WRITE txn
List<ActivityPostEntity> activityPostsToUpdate = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<List<ActivityPostEntity>>() {
public List<ActivityPostEntity> execute() throws Throwable {
// collapse (ie. rollup) and relevant posts
return rollupPosts(activityPosts);
}
}, false);
// update posts + status (note: will also add any new rolled-up posts)
updatePosts(activityPostsToUpdate);
if (logger.isInfoEnabled()) {
int cnt = activityPostsToUpdate.size();
logger.info("Updated: " + cnt + " activity post" + (cnt == 1 ? "" : "s") + " (in " + (System.currentTimeMillis() - start) + " msecs)");
}
}
} catch (LockAcquisitionException e) {
// Job being done by another process
if (logger.isDebugEnabled()) {
logger.debug("execute: Can't get lock. Assume post lookup job already underway: " + e);
}
} catch (SQLException e) {
logger.error("Exception during select of posts: ", e);
throw new JobExecutionException(e);
} catch (Throwable e) {
// If the VM is shutting down, then ignore
if (vmShutdownListener.isVmShuttingDown()) {
// Ignore
} else {
logger.error("Exception during update of posts: ", e);
}
} finally {
releaseLock(lockCallback, lockToken);
}
}
use of org.alfresco.repo.lock.LockAcquisitionException in project alfresco-repository by Alfresco.
the class FeedCleaner method execute.
public int execute() throws JobExecutionException {
checkProperties();
final AtomicBoolean keepGoing = new AtomicBoolean(true);
String lockToken = null;
try {
// Lock
lockToken = jobLockService.getLock(LOCK_QNAME, LOCK_TTL);
// Refresh to get callbacks
JobLockRefreshCallback callback = new JobLockRefreshCallback() {
@Override
public void lockReleased() {
keepGoing.set(false);
}
@Override
public boolean isActive() {
return keepGoing.get();
}
};
jobLockService.refreshLock(lockToken, LOCK_QNAME, LOCK_TTL, callback);
int cleaned = executeWithLock(keepGoing);
if (logger.isDebugEnabled()) {
logger.debug("Cleaned " + cleaned + " feed entries.");
}
} catch (LockAcquisitionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping feed cleaning. " + e.getMessage());
}
} finally {
// Notify the refresh callback that we are done
keepGoing.set(false);
if (lockToken != null) {
jobLockService.releaseLock(lockToken, LOCK_QNAME);
}
}
return 0;
}
use of org.alfresco.repo.lock.LockAcquisitionException in project alfresco-repository by Alfresco.
the class PostCleaner method execute.
public void execute() throws JobExecutionException {
final AtomicBoolean keepGoing = new AtomicBoolean(true);
String lockToken = null;
try {
// Lock
lockToken = jobLockService.getLock(LOCK_QNAME, LOCK_TTL);
// Refresh to get callbacks
JobLockRefreshCallback callback = new JobLockRefreshCallback() {
@Override
public void lockReleased() {
keepGoing.set(false);
}
@Override
public boolean isActive() {
return keepGoing.get();
}
};
jobLockService.refreshLock(lockToken, LOCK_QNAME, LOCK_TTL, callback);
executeWithLock();
} catch (LockAcquisitionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping post cleaning. " + e.getMessage());
}
} finally {
// Notify the refresh callback that we are done
keepGoing.set(false);
if (lockToken != null) {
jobLockService.releaseLock(lockToken, LOCK_QNAME);
}
}
}
use of org.alfresco.repo.lock.LockAcquisitionException in project alfresco-repository by Alfresco.
the class FeedNotifierImpl method execute.
public void execute(int repeatIntervalMins) {
checkProperties();
// Bypass if the system is in read-only mode
if (transactionService.isReadOnly()) {
if (logger.isDebugEnabled()) {
logger.debug("Activities email notification bypassed; the system is read-only");
}
return;
}
String lockToken = null;
// Use a flag to keep track of the running job
final AtomicBoolean running = new AtomicBoolean(true);
try {
lockToken = jobLockService.getLock(LOCK_QNAME, LOCK_TTL);
if (lockToken == null) {
logger.info("Can't get lock. Assume multiple feed notifiers...");
return;
}
if (logger.isTraceEnabled()) {
logger.trace("Activities email notification started");
}
jobLockService.refreshLock(lockToken, LOCK_QNAME, LOCK_TTL, new JobLockRefreshCallback() {
@Override
public boolean isActive() {
return running.get();
}
@Override
public void lockReleased() {
running.set(false);
}
});
executeInternal(repeatIntervalMins);
// Done
if (logger.isTraceEnabled()) {
logger.trace("Activities email notification completed");
}
} catch (LockAcquisitionException e) {
// Job being done by another process
if (logger.isDebugEnabled()) {
logger.debug("Activities email notification already underway");
}
} catch (VmShutdownException e) {
// Aborted
if (logger.isDebugEnabled()) {
logger.debug("Activities email notification aborted");
}
} finally {
// The lock will self-release if answer isActive in the negative
running.set(false);
if (lockToken != null) {
jobLockService.releaseLock(lockToken, LOCK_QNAME);
}
}
}
use of org.alfresco.repo.lock.LockAcquisitionException in project alfresco-repository by Alfresco.
the class UpgradePasswordHashWorker method execute.
/**
* Performs the work, including logging details of progress.
*/
public UpgradePasswordHashWorkResult execute() {
// Build refresh callback
final UpgradePasswordHashWorkResult progress = new UpgradePasswordHashWorkResult();
JobLockRefreshCallback lockCallback = new JobLockRefreshCallback() {
@Override
public void lockReleased() {
progress.inProgress.set(false);
}
@Override
public boolean isActive() {
return progress.inProgress.get();
}
};
String lockToken = null;
try {
progress.inProgress.set(true);
// Get the lock
lockToken = jobLockService.getLock(LOCK, LOCK_TTL);
// Start the refresh timer
jobLockService.refreshLock(lockToken, LOCK, LOCK_TTL, lockCallback);
// Now we know that we'll do something
if (logger.isInfoEnabled()) {
logger.info("Starting upgrade password hash job.");
}
// Do the work
doWork(progress);
// Done
if (logger.isInfoEnabled()) {
logger.info("Finished upgrade password hash job: " + progress);
}
} catch (LockAcquisitionException e) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping upgrade password hash job: " + e.getMessage());
}
} catch (Exception e) {
progress.inProgress.set(false);
logger.error("Upgrade password hash job " + progress);
logger.error("Stopping upgrade password hash job with exception.", e);
} finally {
if (lockToken != null) {
jobLockService.releaseLock(lockToken, LOCK);
}
progress.inProgress.set(false);
}
// Done
return progress;
}
Aggregations