|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hbase.zookeeper.lock.ZKInterProcessLockBase
@InterfaceAudience.Private public abstract class ZKInterProcessLockBase
ZooKeeper based HLock implementation. Based on the Shared Locks recipe. (see: ZooKeeper Recipes and Solutions )
Nested Class Summary | |
---|---|
protected static class |
ZKInterProcessLockBase.AcquiredLock
Represents information about a lock held by this thread. |
protected static class |
ZKInterProcessLockBase.ZNodeComparator
|
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.InterProcessLock |
---|
InterProcessLock.MetadataHandler |
Field Summary | |
---|---|
protected AtomicReference<ZKInterProcessLockBase.AcquiredLock> |
acquiredLock
|
protected String |
fullyQualifiedZNode
|
protected InterProcessLock.MetadataHandler |
handler
|
protected byte[] |
metadata
|
protected String |
parentLockNode
|
protected static String |
READ_LOCK_CHILD_NODE_PREFIX
ZNode prefix used by processes acquiring reader locks |
protected static String |
WRITE_LOCK_CHILD_NODE_PREFIX
ZNode prefix used by processes acquiring writer locks |
protected ZooKeeperWatcher |
zkWatcher
|
Constructor Summary | |
---|---|
protected |
ZKInterProcessLockBase(ZooKeeperWatcher zkWatcher,
String parentLockNode,
byte[] metadata,
InterProcessLock.MetadataHandler handler,
String childNode)
Called by implementing classes. |
Method Summary | |
---|---|
void |
acquire()
Acquire the lock, waiting indefinitely until the lock is released or the thread is interrupted. |
protected abstract String |
getLockPath(String myZNode,
List<String> children)
Determine based on a list of children under a ZNode, whether or not a process which created a specified ZNode has obtained a lock. |
protected boolean |
handleLockMetadata(String lockZNode)
Process metadata stored in a ZNode using a callback object passed to this instance. |
protected static boolean |
isChildWriteLock(String child)
Check if a child znode represents a write lock. |
void |
release()
Release the lock. |
boolean |
tryAcquire(long timeoutMs)
Acquire the lock within a wait time. |
protected void |
updateAcquiredLock(String createdZNode)
Update state as to indicate that a lock is held |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.hadoop.hbase.InterProcessLock |
---|
reapAllLocks |
Field Detail |
---|
protected static final String READ_LOCK_CHILD_NODE_PREFIX
protected static final String WRITE_LOCK_CHILD_NODE_PREFIX
protected final ZooKeeperWatcher zkWatcher
protected final String parentLockNode
protected final String fullyQualifiedZNode
protected final byte[] metadata
protected final InterProcessLock.MetadataHandler handler
protected final AtomicReference<ZKInterProcessLockBase.AcquiredLock> acquiredLock
Constructor Detail |
---|
protected ZKInterProcessLockBase(ZooKeeperWatcher zkWatcher, String parentLockNode, byte[] metadata, InterProcessLock.MetadataHandler handler, String childNode)
zkWatcher
- parentLockNode
- The lock ZNode pathmetadata
- handler
- childNode
- The prefix for child nodes created under the parentMethod Detail |
---|
public void acquire() throws IOException, InterruptedException
acquire
in interface InterProcessLock
IOException
- If there is an unrecoverable error releasing the lock
InterruptedException
- If current thread is interrupted while
waiting for the lockpublic boolean tryAcquire(long timeoutMs) throws IOException, InterruptedException
tryAcquire
in interface InterProcessLock
timeoutMs
- The maximum time (in milliseconds) to wait for the lock,
-1 to wait indefinitely
IOException
- If there is an unrecoverable error talking talking
(e.g., when talking to a lock service) when acquiring
the lock
InterruptedException
- If the thread is interrupted while waiting to
acquire the lockprotected static boolean isChildWriteLock(String child)
child
- The child znode we want to check.
protected void updateAcquiredLock(String createdZNode) throws IOException
createdZNode
- The lock znode
IOException
- If an unrecoverable ZooKeeper error occurspublic void release() throws IOException, InterruptedException
release
in interface InterProcessLock
IOException
- If there is an unrecoverable error releasing the lock
InterruptedException
- If the thread is interrupted while releasing
the lockprotected boolean handleLockMetadata(String lockZNode) throws IOException, InterruptedException
lockZNode
- The node holding the metadata
IOException
- If an unexpected ZooKeeper error occurs
InterruptedException
- If interrupted when reading the metadataprotected abstract String getLockPath(String myZNode, List<String> children) throws IOException, InterruptedException
myZNode
- The ZNode created by the process attempting to acquire
a lockchildren
- List of all child ZNodes under the lock's parent ZNode
IOException
InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |