@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
|
Constructor and Description |
---|
IdLock() |
Modifier and Type | Method and Description |
---|---|
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) |
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)
public void waitForWaiters(long id, int numWaiters) throws InterruptedException
InterruptedException
Copyright © 2007–2019 Cloudera. All rights reserved.