java.lang.AutoCloseablepublic class Locker
extends java.lang.Object
implements java.lang.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 | Description |
|---|---|
Locker(InterProcessLock lock) |
|
Locker(InterProcessLock lock,
long timeout,
java.util.concurrent.TimeUnit unit) |
| Modifier and Type | Method | Description |
|---|---|---|
protected void |
acquireLock(InterProcessLock lock) |
|
protected boolean |
acquireLock(InterProcessLock lock,
long timeout,
java.util.concurrent.TimeUnit unit) |
|
void |
close() |
|
protected void |
releaseLock() |
public Locker(InterProcessLock lock, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
lock - a lock implementation (e.g. InterProcessMutex, InterProcessSemaphoreV2, etc.)timeout - max timeout to acquire lockunit - time unit of timeoutjava.lang.Exception - Curator errors or TimeoutException if the lock cannot be acquired within the timeoutpublic Locker(InterProcessLock lock) throws java.lang.Exception
lock - a lock implementation (e.g. InterProcessMutex, InterProcessSemaphoreV2, etc.)java.lang.Exception - errorspublic void close()
throws java.lang.Exception
close in interface java.lang.AutoCloseablejava.lang.Exceptionprotected void releaseLock()
throws java.lang.Exception
java.lang.Exceptionprotected void acquireLock(InterProcessLock lock) throws java.lang.Exception
java.lang.Exceptionprotected boolean acquireLock(InterProcessLock lock, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
java.lang.ExceptionCopyright © 2011–2018 The Apache Software Foundation. All rights reserved.