Package org.somda.sdc.common.util
Class AutoLock<T extends Lock>
java.lang.Object
org.somda.sdc.common.util.AutoLock<T>
- Type Parameters:
T- the lock type to auto-close.
- All Implemented Interfaces:
AutoCloseable,Lock
Converts locks to auto-closables.
-
Method Details
-
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
Returns the wrapped lock instance.- Returns:
- the wrapped lock.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
lock
public void lock() -
lockInterruptibly
- Specified by:
lockInterruptiblyin interfaceLock- Throws:
InterruptedException
-
tryLock
public boolean tryLock() -
tryLock
- Specified by:
tryLockin interfaceLock- Throws:
InterruptedException
-
unlock
public void unlock() -
newCondition
- Specified by:
newConditionin interfaceLock
-