Class LockManagerUtils


  • public class LockManagerUtils
    extends Object
    • Constructor Detail

      • LockManagerUtils

        public LockManagerUtils()
    • Method Detail

      • waitForLock

        public static LockResource waitForLock​(LockManager lockManager,
                                               String key,
                                               long waitInterval,
                                               long maxWait)
                                        throws LockException,
                                               TimeoutException,
                                               InterruptedException

        Utility method to create and if needed wait for a maximum amount of time (unless interrupted) for a LockManager.lock(String) *

        Make sure that after obtaining the cluster-wide lock, that in you are doing JCR node invocations, you first invoke

                   session.refresh(true|false)
               
        to make sure the latest global JCR cluster changes are retrieved locally.

        Parameters:
        lockManager - lockManager
        key - the key for the Lock where key is now allowed to exceed 256 chars
        waitInterval - time in milliseconds to wait before retrying creating the lock
        maxWait - maximum time in milliseconds for trying to create the lock, will throw TimeoutException when exceeded.
        Returns:
        LockResource such that this waitForLock(LockManager, String, long) method can be used in a try-with-resources statement where the LockResource.close() results in the lock being freed.
        Throws:
        LockException - if the lock could not be created (other then AlreadyLockedException)
        TimeoutException - when the maxWait time has exceeded while trying to create the lock
        InterruptedException - when the thread is interrupted while waiting before retrying to create the lock