Package org.apache.hadoop.hbase.util
Class IdLock
java.lang.Object
org.apache.hadoop.hbase.util.IdLock
Allows multiple concurrent clients to lock on a numeric id with a minimal memory overhead. The
intended usage is as follows:
IdLock.Entry lockEntry = idLock.getLockEntry(id); try { // User code. } finally { idLock.releaseLockEntry(lockEntry); }
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
An entry returned to the client as a lock object -
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private ConcurrentMap<Long,
IdLock.Entry> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) void
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.tryLockEntry
(long id, long time) Blocks until the lock corresponding to the given id is acquired.void
waitForWaiters
(long id, int numWaiters)
-
Field Details
-
LOG
-
map
-
-
Constructor Details
-
IdLock
public IdLock()
-
-
Method Details
-
getLockEntry
Blocks until the lock corresponding to the given id is acquired.- Parameters:
id
- an arbitrary number to lock on- Returns:
- an "entry" to pass to
releaseLockEntry(Entry)
to release the lock - Throws:
IOException
- if interrupted
-
tryLockEntry
Blocks until the lock corresponding to the given id is acquired.- Parameters:
id
- an arbitrary number to lock ontime
- time to wait in ms- Returns:
- an "entry" to pass to
releaseLockEntry(Entry)
to release the lock - Throws:
IOException
- if interrupted
-
releaseLockEntry
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.- Parameters:
entry
- the return value ofgetLockEntry(long)
-
isHeldByCurrentThread
Test whether the given id is already locked by the current thread. -
assertMapEmpty
void assertMapEmpty() -
waitForWaiters
- Throws:
InterruptedException
-