Class ZooLock
- java.lang.Object
-
- org.apache.accumulo.fate.zookeeper.ZooLock
-
- All Implemented Interfaces:
org.apache.zookeeper.Watcher
public class ZooLock extends Object implements org.apache.zookeeper.Watcher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ZooLock.AsyncLockWatcher
static class
ZooLock.LockLossReason
static interface
ZooLock.LockWatcher
-
Field Summary
Fields Modifier and Type Field Description static String
LOCK_PREFIX
protected IZooReaderWriter
zooKeeper
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
deleteLock(IZooReaderWriter zk, String path)
static boolean
deleteLock(IZooReaderWriter zk, String path, String lockData)
static byte[]
getLockData(ZooCache zc, String path, ZooCache.ZcStat 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)
void
lockAsync(ZooLock.AsyncLockWatcher lw, byte[] data)
void
process(org.apache.zookeeper.WatchedEvent event)
void
replaceLockData(byte[] b)
boolean
tryLock(ZooLock.LockWatcher lw, byte[] data)
boolean
tryToCancelAsyncLockOrUnlock()
void
unlock()
boolean
wasLockAcquired()
indicates if the lock was acquired in the past....
-
-
-
Field Detail
-
LOCK_PREFIX
public static final String LOCK_PREFIX
- See Also:
- Constant Field Values
-
zooKeeper
protected final IZooReaderWriter zooKeeper
-
-
Constructor Detail
-
ZooLock
public ZooLock(ZooReaderWriter zoo, String path)
-
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 acquired, otherwise false.
-
isLocked
public boolean isLocked()
-
replaceLockData
public void replaceLockData(byte[] b) throws org.apache.zookeeper.KeeperException, InterruptedException
- Throws:
org.apache.zookeeper.KeeperException
InterruptedException
-
process
public void process(org.apache.zookeeper.WatchedEvent event)
- Specified by:
process
in interfaceorg.apache.zookeeper.Watcher
-
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, ZooCache.ZcStat stat)
-
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
-
-