org.apache.accumulo.fate.zookeeper
Class ZooLock

java.lang.Object
  extended by org.apache.accumulo.fate.zookeeper.ZooLock
All Implemented Interfaces:
org.apache.zookeeper.Watcher
Direct Known Subclasses:
ZooLock

public class ZooLock
extends Object
implements org.apache.zookeeper.Watcher


Nested Class Summary
static interface ZooLock.AsyncLockWatcher
           
static class ZooLock.LockLossReason
           
static interface ZooLock.LockWatcher
           
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event
 
Field Summary
static String LOCK_PREFIX
           
protected static org.apache.log4j.Logger log
           
protected  IZooReaderWriter zooKeeper
           
 
Constructor Summary
  ZooLock(String zookeepers, int timeInMillis, String scheme, byte[] auth, String path)
           
protected ZooLock(ZooCache zc, IZooReaderWriter zrw, String path)
           
 
Method Summary
static void deleteLock(IZooReaderWriter zk, String path)
           
static boolean deleteLock(IZooReaderWriter zk, String path, String lockData)
           
static byte[] getLockData(String path)
           
static byte[] getLockData(String path, org.apache.zookeeper.data.Stat stat)
           
static byte[] getLockData(ZooCache zc, String path, org.apache.zookeeper.data.Stat stat)
           
static byte[] getLockData(org.apache.zookeeper.ZooKeeper zk, String path)
           
 ZooUtil.LockID getLockID()
           
 String getLockName()
           
 String getLockPath()
           
 long getSessionId()
           
static long getSessionId(ZooCache zc, String path)
           
 boolean isLocked()
           
static boolean isLockHeld(ZooCache zc, ZooUtil.LockID lid)
           
static boolean isLockHeld(org.apache.zookeeper.ZooKeeper zk, ZooUtil.LockID lid)
           
 void lockAsync(ZooLock.AsyncLockWatcher lw, byte[] data)
           
 void process(org.apache.zookeeper.WatchedEvent event)
           
 boolean tryLock(ZooLock.LockWatcher lw, byte[] data)
           
 boolean tryToCancelAsyncLockOrUnlock()
           
 void unlock()
           
 boolean wasLockAcquired()
          indicates if the lock was acquired in the past....
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

LOCK_PREFIX

public static final String LOCK_PREFIX
See Also:
Constant Field Values

zooKeeper

protected final IZooReaderWriter zooKeeper
Constructor Detail

ZooLock

public ZooLock(String zookeepers,
               int timeInMillis,
               String scheme,
               byte[] auth,
               String path)

ZooLock

protected ZooLock(ZooCache zc,
                  IZooReaderWriter zrw,
                  String path)
Method Detail

tryLock

public boolean tryLock(ZooLock.LockWatcher lw,
                       byte[] data)
                throws org.apache.zookeeper.KeeperException,
                       InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

lockAsync

public void lockAsync(ZooLock.AsyncLockWatcher lw,
                      byte[] data)

tryToCancelAsyncLockOrUnlock

public boolean tryToCancelAsyncLockOrUnlock()
                                     throws InterruptedException,
                                            org.apache.zookeeper.KeeperException
Throws:
InterruptedException
org.apache.zookeeper.KeeperException

unlock

public void unlock()
            throws InterruptedException,
                   org.apache.zookeeper.KeeperException
Throws:
InterruptedException
org.apache.zookeeper.KeeperException

getLockPath

public String getLockPath()

getLockName

public String getLockName()

getLockID

public ZooUtil.LockID getLockID()

wasLockAcquired

public boolean wasLockAcquired()
indicates if the lock was acquired in the past.... helps discriminate between the case where the lock was never held, or held and lost....

Returns:
true if the lock was aquired, otherwise false.

isLocked

public boolean isLocked()

process

public void process(org.apache.zookeeper.WatchedEvent event)
Specified by:
process in interface org.apache.zookeeper.Watcher

isLockHeld

public static boolean isLockHeld(org.apache.zookeeper.ZooKeeper zk,
                                 ZooUtil.LockID lid)
                          throws org.apache.zookeeper.KeeperException,
                                 InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

isLockHeld

public static boolean isLockHeld(ZooCache zc,
                                 ZooUtil.LockID lid)

getLockData

public static byte[] getLockData(org.apache.zookeeper.ZooKeeper zk,
                                 String path)
                          throws org.apache.zookeeper.KeeperException,
                                 InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getLockData

public static byte[] getLockData(ZooCache zc,
                                 String path,
                                 org.apache.zookeeper.data.Stat stat)

getLockData

public static byte[] getLockData(String path)

getLockData

public static byte[] getLockData(String path,
                                 org.apache.zookeeper.data.Stat stat)

getSessionId

public static long getSessionId(ZooCache zc,
                                String path)
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getSessionId

public long getSessionId()
                  throws org.apache.zookeeper.KeeperException,
                         InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

deleteLock

public static void deleteLock(IZooReaderWriter zk,
                              String path)
                       throws InterruptedException,
                              org.apache.zookeeper.KeeperException
Throws:
InterruptedException
org.apache.zookeeper.KeeperException

deleteLock

public static boolean deleteLock(IZooReaderWriter zk,
                                 String path,
                                 String lockData)
                          throws InterruptedException,
                                 org.apache.zookeeper.KeeperException
Throws:
InterruptedException
org.apache.zookeeper.KeeperException


Copyright © 2013 Apache Accumulo Project. All Rights Reserved.