Class Locker
java.lang.Object
org.apache.curator.framework.recipes.locks.Locker
- All Implemented Interfaces:
AutoCloseable
Utility for safely acquiring a lock and releasing it using Java 7's try-with-resource feature.
Canonical usage:
InterProcessMutex mutex = new InterProcessMutex(...) // or any InterProcessLock
try ( Locker locker = new Locker(mutex, maxTimeout, unit) )
{
// do work
}
-
Constructor Summary
ConstructorsConstructorDescriptionLocker(InterProcessLock lock) Locker(InterProcessLock lock, long timeout, TimeUnit unit) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidacquireLock(InterProcessLock lock) protected booleanacquireLock(InterProcessLock lock, long timeout, TimeUnit unit) voidclose()protected void
-
Constructor Details
-
Locker
- Parameters:
lock- a lock implementation (e.g.InterProcessMutex,InterProcessSemaphoreV2, etc.)timeout- max timeout to acquire lockunit- time unit of timeout- Throws:
Exception- Curator errors orTimeoutExceptionif the lock cannot be acquired within the timeout
-
Locker
- Parameters:
lock- a lock implementation (e.g.InterProcessMutex,InterProcessSemaphoreV2, etc.)- Throws:
Exception- errors
-
-
Method Details