org.apache.hadoop.hbase.util
Class IdLock

java.lang.Object
  extended by org.apache.hadoop.hbase.util.IdLock

@InterfaceAudience.Private
public class IdLock
extends Object

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
static class IdLock.Entry
          An entry returned to the client as a lock object
 
Constructor Summary
IdLock()
           
 
Method Summary
 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)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IdLock

public IdLock()
Method Detail

getLockEntry

public IdLock.Entry getLockEntry(long id)
                          throws IOException
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

releaseLockEntry

public 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.

Parameters:
entry - the return value of getLockEntry(long)

waitForWaiters

public void waitForWaiters(long id,
                           int numWaiters)
                    throws InterruptedException
Throws:
InterruptedException


Copyright © 2015 The Apache Software Foundation. All rights reserved.