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
ConstructorDescriptionLocker
(InterProcessLock lock) Locker
(InterProcessLock lock, long timeout, TimeUnit unit) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
acquireLock
(InterProcessLock lock) protected boolean
acquireLock
(InterProcessLock lock, long timeout, TimeUnit unit) void
close()
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 orTimeoutException
if the lock cannot be acquired within the timeout
-
Locker
- Parameters:
lock
- a lock implementation (e.g.InterProcessMutex
,InterProcessSemaphoreV2
, etc.)- Throws:
Exception
- errors
-
-
Method Details