|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.bigdata.zookeeper.ZNodeLockWatcher.ZLockImpl
protected static class ZNodeLockWatcher.ZLockImpl
ZLock implementation class. The lock is realized as an EPHEMERAL
SEQUENTIAL child of the lock node. If the child is in the first position
of the lexically sorted children then it holds the lock.
Note: Assuming it has the correct ACL, any thread in any process MAY release the lock, NOT just the one that acquired it. This is done by deleting the ephemeral znode corresponding to the process holding the lock.
| Field Summary | |
|---|---|
protected List<org.apache.zookeeper.data.ACL> |
acl
|
protected org.apache.zookeeper.ZooKeeper |
zookeeper
|
protected String |
zpath
The zpath of the lock node (the parent node whose ephemeral sequential children represent the queue of processes contending for the lock). |
| Constructor Summary | |
|---|---|
protected |
ZNodeLockWatcher.ZLockImpl(org.apache.zookeeper.ZooKeeper zookeeper,
String zpath,
List<org.apache.zookeeper.data.ACL> acl)
|
| Method Summary | |
|---|---|
void |
destroyLock()
Creates a marker node (a sibling of the lock node) to prevent new children from being added to the queue and then deletes all children in the queue in reverse lexical order so as to not trigger cascades of watchers and finally deletes the lock node itself and then the marker node. |
String |
getChild()
The znode (not zpath) of the child and null iff the
child does not hold the lock. |
String |
getZPath()
The zpath of the lock node. |
boolean |
isLockHeld()
Return true if the lock is currently held (this verifies
that the zchild for the lock is in fact the leader in the queue of
ephemeral znodes contending for the lock). |
void |
lock()
Acquire the lock (blocking). |
void |
lock(long timeout,
TimeUnit unit)
Creates a new lock request (an EPHEMERAL SEQUENTIAL znode that is a child of the lock node) and awaits up to the timeout for the ZLock to
be granted. |
String |
toString()
Non-blocking representation of lock state. |
void |
unlock()
Note: In the case where the lock was stolen by deleting the zchild node this method logs a warning but does not throw an exception. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected final org.apache.zookeeper.ZooKeeper zookeeper
protected final String zpath
protected final List<org.apache.zookeeper.data.ACL> acl
| Constructor Detail |
|---|
protected ZNodeLockWatcher.ZLockImpl(org.apache.zookeeper.ZooKeeper zookeeper,
String zpath,
List<org.apache.zookeeper.data.ACL> acl)
zookeeper - zpath - The zpath of the lock node.acl - | Method Detail |
|---|
public String toString()
toString in class Objectpublic String getZPath()
public String getChild()
throws InterruptedException
null iff the
child does not hold the lock.
InterruptedException
public void lock()
throws org.apache.zookeeper.KeeperException,
InterruptedException
ZLock
lock in interface ZLockorg.apache.zookeeper.KeeperException - if the lock node or the ephemeral child could not be
created.
org.apache.zookeeper.KeeperException.SessionExpiredException - If the ZooKeeper client's session was expired. note
that this exception is non-recoverable for a given
ZooKeeper instance. However, if the application
handles the exception according to its own semantics then it
MAY obtain a new ZooKeeper instance associated with a
new session.
InterruptedException - if the thread was interrupted while awaiting the lock.
public boolean isLockHeld()
throws org.apache.zookeeper.KeeperException,
InterruptedException
ZLocktrue if the lock is currently held (this verifies
that the zchild for the lock is in fact the leader in the queue of
ephemeral znodes contending for the lock).
isLockHeld in interface ZLocktrue iff the lock is held.
org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException.SessionExpiredException - If the ZooKeeper client's session was expired. note
that this exception is non-recoverable for a given
ZooKeeper instance. However, if the application
handles the exception according to its own semantics then it
MAY obtain a new ZooKeeper instance associated with a
new session.
InterruptedException
public void lock(long timeout,
TimeUnit unit)
throws org.apache.zookeeper.KeeperException,
InterruptedException,
TimeoutException
ZLockZLock to
be granted.
lock in interface ZLocktimeout - The timeout.unit - The unit in which that timeout is expressed.
org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException.SessionExpiredException - If the ZooKeeper client's session was expired. note
that this exception is non-recoverable for a given
ZooKeeper instance. However, if the application
handles the exception according to its own semantics then it
MAY obtain a new ZooKeeper instance associated with a
new session.
InterruptedException - if the thread was interrupted while awaiting the lock.
TimeoutException - if the timeout noticeably expired before the lock was
granted.
public void unlock()
throws org.apache.zookeeper.KeeperException,
InterruptedException
unlock in interface ZLockorg.apache.zookeeper.KeeperException
InterruptedException
public void destroyLock()
throws org.apache.zookeeper.KeeperException,
InterruptedException
destroyLock in interface ZLockorg.apache.zookeeper.KeeperException
InterruptedExceptionunlock() succeeds after destroyLock(), consider allowing even if you do not hold the lock., consider what happens if there is a transient disconnect.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||