Search in sources :

Example 1 with VmShutdownException

use of org.alfresco.util.VmShutdownListener.VmShutdownException 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);
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JobLockRefreshCallback(org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback) VmShutdownException(org.alfresco.util.VmShutdownListener.VmShutdownException) LockAcquisitionException(org.alfresco.repo.lock.LockAcquisitionException)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JobLockRefreshCallback (org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback)1 LockAcquisitionException (org.alfresco.repo.lock.LockAcquisitionException)1 VmShutdownException (org.alfresco.util.VmShutdownListener.VmShutdownException)1