Package org.somda.sdc.common.util
Class AutoLock<T extends Lock>
- java.lang.Object
-
- org.somda.sdc.common.util.AutoLock<T>
-
- All Implemented Interfaces:
AutoCloseable,Lock
public class AutoLock<T extends Lock> extends Object implements Lock, AutoCloseable
Converts locks to auto-closables.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()TgetLock()Returns the wrapped lock instance.voidlock()static <T extends Lock>
AutoLocklock(T lock)Locks the given lock and return auto-closable variant.voidlockInterruptibly()ConditionnewCondition()booleantryLock()booleantryLock(long time, TimeUnit unit)voidunlock()
-
-
-
Method Detail
-
lock
public static <T extends Lock> AutoLock lock(T lock)
Locks the given lock and return auto-closable variant.- Type Parameters:
T- type of the lock (write/read/common).- Parameters:
lock- the lock to wrap.- Returns:
- an auto-closable instance to be used with
try (...) { ... }.
-
getLock
public T getLock()
Returns the wrapped lock instance.- Returns:
- the wrapped lock.
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
lockInterruptibly
public void lockInterruptibly() throws InterruptedException- Specified by:
lockInterruptiblyin interfaceLock- Throws:
InterruptedException
-
tryLock
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException- Specified by:
tryLockin interfaceLock- Throws:
InterruptedException
-
newCondition
public Condition newCondition()
- Specified by:
newConditionin interfaceLock
-
-