@InterfaceAudience.Private public class IdLock extends Object
IdLock.Entry lockEntry = idLock.getLockEntry(id); try { // User code. } finally { idLock.releaseLockEntry(lockEntry); }
Modifier and Type | Class and Description |
---|---|
static class |
IdLock.Entry
An entry returned to the client as a lock object
|
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
LOG |
private ConcurrentMap<Long,IdLock.Entry> |
map |
Constructor and Description |
---|
IdLock() |
Modifier and Type | Method and Description |
---|---|
(package private) void |
assertMapEmpty() |
IdLock.Entry |
getLockEntry(long id)
Blocks until the lock corresponding to the given id is acquired.
|
boolean |
isHeldByCurrentThread(long id)
Test whether the given id is already locked by the current thread.
|
void |
releaseLockEntry(IdLock.Entry entry)
Must be called in a finally block to decrease the internal counter and remove the monitor
object for the given id if the caller is the last client.
|
IdLock.Entry |
tryLockEntry(long id,
long time)
Blocks until the lock corresponding to the given id is acquired.
|
void |
waitForWaiters(long id,
int numWaiters) |
private static final org.slf4j.Logger LOG
private ConcurrentMap<Long,IdLock.Entry> map
public IdLock()
public IdLock.Entry getLockEntry(long id) throws IOException
id
- an arbitrary number to lock onreleaseLockEntry(Entry)
to release
the lockIOException
- if interruptedpublic IdLock.Entry tryLockEntry(long id, long time) throws IOException
id
- an arbitrary number to lock ontime
- time to wait in msreleaseLockEntry(Entry)
to release
the lockIOException
- if interruptedpublic void releaseLockEntry(IdLock.Entry entry)
entry
- the return value of getLockEntry(long)
public boolean isHeldByCurrentThread(long id)
void assertMapEmpty()
public void waitForWaiters(long id, int numWaiters) throws InterruptedException
InterruptedException
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.