Class Locker
- java.lang.Object
-
- org.apache.curator.framework.recipes.locks.Locker
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class Locker extends java.lang.Object implements java.lang.AutoCloseableUtility 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
Constructors Constructor Description Locker(InterProcessLock lock)Locker(InterProcessLock lock, long timeout, java.util.concurrent.TimeUnit unit)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidacquireLock(InterProcessLock lock)protected booleanacquireLock(InterProcessLock lock, long timeout, java.util.concurrent.TimeUnit unit)voidclose()protected voidreleaseLock()
-
-
-
Constructor Detail
-
Locker
public Locker(InterProcessLock lock, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
- Parameters:
lock- a lock implementation (e.g.InterProcessMutex,InterProcessSemaphoreV2, etc.)timeout- max timeout to acquire lockunit- time unit of timeout- Throws:
java.lang.Exception- Curator errors orTimeoutExceptionif the lock cannot be acquired within the timeout
-
Locker
public Locker(InterProcessLock lock) throws java.lang.Exception
- Parameters:
lock- a lock implementation (e.g.InterProcessMutex,InterProcessSemaphoreV2, etc.)- Throws:
java.lang.Exception- errors
-
-
Method Detail
-
close
public void close() throws java.lang.Exception- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
java.lang.Exception
-
releaseLock
protected void releaseLock() throws java.lang.Exception- Throws:
java.lang.Exception
-
acquireLock
protected void acquireLock(InterProcessLock lock) throws java.lang.Exception
- Throws:
java.lang.Exception
-
acquireLock
protected boolean acquireLock(InterProcessLock lock, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.Exception
- Throws:
java.lang.Exception
-
-