org.apache.hadoop.hbase.util
Class KeyLocker<K extends Comparable<? super K>>

java.lang.Object
  extended by org.apache.hadoop.hbase.util.KeyLocker<K>

@InterfaceAudience.Private
public class KeyLocker<K extends Comparable<? super K>>
extends Object

A utility class to manage a set of locks. Each lock is identified by a String which serves as a key. Typical usage is:

class Example{ private final static KeyLocker locker = new Locker();

public void foo(String s){ Lock lock = locker.acquireLock(s); try { // whatever }finally{ lock.unlock(); } } }


Constructor Summary
KeyLocker()
           
 
Method Summary
 ReentrantLock acquireLock(K key)
          Return a lock for the given key.
 Map<K,Lock> acquireLocks(Set<K> keys)
          Acquire locks for a set of keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyLocker

public KeyLocker()
Method Detail

acquireLock

public ReentrantLock acquireLock(K key)
Return a lock for the given key. The lock is already locked.

Parameters:
key -

acquireLocks

public Map<K,Lock> acquireLocks(Set<K> keys)
Acquire locks for a set of keys. The keys will be sorted internally to avoid possible deadlock.



Copyright © 2015 The Apache Software Foundation. All Rights Reserved.