Search in sources :

Example 1 with JobLockRefreshCallback

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

Example 2 with JobLockRefreshCallback

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

Example 3 with JobLockRefreshCallback

use of org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback 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)

Example 4 with JobLockRefreshCallback

use of org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback 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;
}
Also used : JobLockRefreshCallback(org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) BeansException(org.springframework.beans.BeansException) JobExecutionException(org.quartz.JobExecutionException) LockAcquisitionException(org.alfresco.repo.lock.LockAcquisitionException) LockAcquisitionException(org.alfresco.repo.lock.LockAcquisitionException)

Example 5 with JobLockRefreshCallback

use of org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback in project alfresco-repository by Alfresco.

the class SolrBackupClient method execute.

public void execute() {
    if (solrQueryHTTPClient.isSharded()) {
        return;
    }
    String lockToken = getLock(60000);
    if (lockToken == null) {
        return;
    }
    // Use a flag to keep track of the running job
    final AtomicBoolean running = new AtomicBoolean(true);
    jobLockService.refreshLock(lockToken, lock, 30000, new JobLockRefreshCallback() {

        @Override
        public boolean isActive() {
            return running.get();
        }

        @Override
        public void lockReleased() {
            running.set(false);
        }
    });
    try {
        executeImpl(running);
    } catch (RuntimeException e) {
        throw e;
    } finally {
        // The lock will self-release if answer isActive in the negative
        running.set(false);
        jobLockService.releaseLock(lockToken, lock);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) JobLockRefreshCallback(org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback)

Aggregations

JobLockRefreshCallback (org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback)9 LockAcquisitionException (org.alfresco.repo.lock.LockAcquisitionException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 QName (org.alfresco.service.namespace.QName)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 JobExecutionException (org.quartz.JobExecutionException)2 BeansException (org.springframework.beans.BeansException)2 VmShutdownException (org.alfresco.util.VmShutdownListener.VmShutdownException)1 Level (org.apache.log4j.Level)1