Class LockManagerUtils
- java.lang.Object
-
- org.onehippo.cms7.services.lock.LockManagerUtils
-
public class LockManagerUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description LockManagerUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static LockResource
waitForLock(LockManager lockManager, String key, long waitInterval)
Utility method to create and if needed wait indefinitely (unless interrupted) for aLockManager.lock(String)
.static LockResource
waitForLock(LockManager lockManager, String key, long waitInterval, long maxWait)
Utility method to create and if needed wait for a maximum amount of time (unless interrupted) for aLockManager.lock(String)
*
-
-
-
Method Detail
-
waitForLock
public static LockResource waitForLock(LockManager lockManager, String key, long waitInterval) throws LockException, InterruptedException
Utility method to create and if needed wait indefinitely (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)
- Parameters:
lockManager
- lockManagerkey
- the key for theLock
wherekey
is now allowed to exceed 256 charswaitInterval
- time in milliseconds to wait before retrying creating the lock- Returns:
LockResource
such that thiswaitForLock(LockManager, String, long)
method can be used in a try-with-resources statement where theLockResource.close()
results in the lock being freed.- Throws:
LockException
- if the lock could not be created (other thenAlreadyLockedException
)InterruptedException
- when the thread is interrupted while waiting before retrying to create the lock
-
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)
- Parameters:
lockManager
- lockManagerkey
- the key for theLock
wherekey
is now allowed to exceed 256 charswaitInterval
- time in milliseconds to wait before retrying creating the lockmaxWait
- maximum time in milliseconds for trying to create the lock, will throw TimeoutException when exceeded.- Returns:
LockResource
such that thiswaitForLock(LockManager, String, long)
method can be used in a try-with-resources statement where theLockResource.close()
results in the lock being freed.- Throws:
LockException
- if the lock could not be created (other thenAlreadyLockedException
)TimeoutException
- when the maxWait time has exceeded while trying to create the lockInterruptedException
- when the thread is interrupted while waiting before retrying to create the lock
-
-