@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 ConcurrentMap<Long,IdLock.Entry> |
map |
Constructor and Description |
---|
IdLock() |
Modifier and Type | Method and Description |
---|---|
(package private) void |
assertMapEmpty()
For testing
|
IdLock.Entry |
getLockEntry(long id)
Blocks until the lock corresponding to the given id is acquired.
|
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.
|
void |
waitForWaiters(long id,
int numWaiters) |
private ConcurrentMap<Long,IdLock.Entry> map
public IdLock.Entry getLockEntry(long id) throws IOException
id
- an arbitrary number to lock onreleaseLockEntry(Entry)
to release
the lockIOException
- if interruptedpublic void releaseLockEntry(IdLock.Entry entry)
entry
- the return value of getLockEntry(long)
void assertMapEmpty()
public void waitForWaiters(long id, int numWaiters) throws InterruptedException
InterruptedException
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.