public class AdaptedSemaphoreNamedLock extends NamedLockSupport
| Modifier and Type | Class and Description |
|---|---|
static interface |
AdaptedSemaphoreNamedLock.AdaptedSemaphore
Wrapper for semaphore-like stuff, that do not share common ancestor.
|
| Modifier and Type | Field and Description |
|---|---|
private static int |
EXCLUSIVE
Count of permissions involved with exclusive locking
|
private static int |
NONE
Count of permissions involved with "nop" locking.
|
private AdaptedSemaphoreNamedLock.AdaptedSemaphore |
semaphore |
private static int |
SHARED
Count of permissions involved with shared locking
|
private java.lang.ThreadLocal<java.util.Deque<java.lang.Integer>> |
threadPerms |
logger| Constructor and Description |
|---|
AdaptedSemaphoreNamedLock(java.lang.String name,
NamedLockFactorySupport factory,
AdaptedSemaphoreNamedLock.AdaptedSemaphore semaphore) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
lockExclusively(long time,
java.util.concurrent.TimeUnit unit)
Tries to lock exclusively, may block for given time.
|
boolean |
lockShared(long time,
java.util.concurrent.TimeUnit unit)
Tries to lock shared, may block for given time.
|
void |
unlock()
Unlocks the lock, must be invoked by caller after one of the
NamedLock.lockShared(long, TimeUnit) or NamedLock.lockExclusively(long, TimeUnit). |
close, nameprivate static final int NONE
private static final int SHARED
private static final int EXCLUSIVE
private final java.lang.ThreadLocal<java.util.Deque<java.lang.Integer>> threadPerms
private final AdaptedSemaphoreNamedLock.AdaptedSemaphore semaphore
public AdaptedSemaphoreNamedLock(java.lang.String name,
NamedLockFactorySupport factory,
AdaptedSemaphoreNamedLock.AdaptedSemaphore semaphore)
public boolean lockShared(long time,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
NamedLocktrue.java.lang.InterruptedExceptionpublic boolean lockExclusively(long time,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
NamedLocktrue.java.lang.InterruptedExceptionpublic void unlock()
NamedLockNamedLock.lockShared(long, TimeUnit) or NamedLock.lockExclusively(long, TimeUnit).