Package org.kiwiproject.curator
Class CuratorLockHelper
- java.lang.Object
-
- org.kiwiproject.curator.CuratorLockHelper
-
public class CuratorLockHelper extends Object
Helper class for creating and managing Curator locks, and converting timeouts and exceptions thrown by Curator intoLockAcquisitionExceptions.
-
-
Constructor Summary
Constructors Constructor Description CuratorLockHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacquire(org.apache.curator.framework.recipes.locks.InterProcessLock lock, long time, TimeUnit unit)Tries to acquire the specifiedlock, waiting up to the specified timeout period.org.apache.curator.framework.recipes.locks.InterProcessMutexcreateInterProcessMutex(org.apache.curator.framework.CuratorFramework client, String lockPath)Creates a Curator lock instance for the given path.voidreleaseLockQuietlyIfHeld(org.apache.curator.framework.recipes.locks.InterProcessLock lock)Release the given lock quietly (ignoring exceptions) if the current process holds it.voidreleaseQuietly(org.apache.curator.framework.recipes.locks.InterProcessLock lock)Release the given lock, ignoring ifnullor if any exception occurs releasing the lock.
-
-
-
Method Detail
-
createInterProcessMutex
public org.apache.curator.framework.recipes.locks.InterProcessMutex createInterProcessMutex(org.apache.curator.framework.CuratorFramework client, String lockPath)Creates a Curator lock instance for the given path.- Parameters:
client- Curator clientlockPath- the ZooKeeper base lock path- Returns:
- a Curator lock instance (
InterProcessMutex)
-
acquire
public void acquire(org.apache.curator.framework.recipes.locks.InterProcessLock lock, long time, TimeUnit unit)Tries to acquire the specifiedlock, waiting up to the specified timeout period. If Curator throws any exception, or if the timeout expires, the appropriate exception is thrown.- Parameters:
lock- the lock to acquiretime- the timeout quantityunit- the timeout unit- Throws:
LockAcquisitionFailureException- if the lock throws any exception during acquisitionLockAcquisitionTimeoutException- if the lock acquisition times out
-
releaseQuietly
public void releaseQuietly(org.apache.curator.framework.recipes.locks.InterProcessLock lock)
Release the given lock, ignoring ifnullor if any exception occurs releasing the lock.- Parameters:
lock- to release
-
releaseLockQuietlyIfHeld
public void releaseLockQuietlyIfHeld(org.apache.curator.framework.recipes.locks.InterProcessLock lock)
Release the given lock quietly (ignoring exceptions) if the current process holds it.- Parameters:
lock- to release, if held
-
-