org.linkedin.zookeeper.tracker
Class ZooKeeperTreeTracker<T>
java.lang.Object
org.linkedin.zookeeper.tracker.ZooKeeperTreeTracker<T>
- All Implemented Interfaces:
- org.linkedin.util.lifecycle.Destroyable, org.linkedin.util.lifecycle.Terminable
public class ZooKeeperTreeTracker<T>
- extends java.lang.Object
- implements org.linkedin.util.lifecycle.Destroyable
The purpose of this class is to essentially keep a replica of ZooKeeper data in memory and
be able to be notified when it changes.
|
Field Summary |
org.linkedin.util.clock.Clock |
clock
|
static org.slf4j.Logger |
log
|
static java.lang.String |
MODULE
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MODULE
public static final java.lang.String MODULE
log
public static final org.slf4j.Logger log
clock
public org.linkedin.util.clock.Clock clock
ZooKeeperTreeTracker
public ZooKeeperTreeTracker(IZKClient zk,
ZKDataReader<T> zkDataReader,
java.lang.String root)
ZooKeeperTreeTracker
public ZooKeeperTreeTracker(IZKClient zk,
ZKDataReader<T> zkDataReader,
java.lang.String root,
int depth)
computeAbsoluteDepth
public static int computeAbsoluteDepth(java.lang.String path)
getRoot
public java.lang.String getRoot()
getZKCient
public IZKClient getZKCient()
getDepth
public int getDepth()
getLastZkTxId
public long getLastZkTxId()
waitForZkTxId
public long waitForZkTxId(long zkTxId,
java.lang.Object timeout)
throws java.util.concurrent.TimeoutException,
java.lang.InterruptedException
- Waits no longer than the timeout provided (or forever if
null) for this tracker
to have seen at least the provided zookeeper transaction id
- Returns:
- the last known zkTxId (guaranteed to be >= to zkTxId)
- Throws:
java.util.concurrent.TimeoutException
java.lang.InterruptedException
destroy
public void destroy()
- It is not possible to remove a watcher... so we just set the tracker in destroyed mode which
will simply ignore all subsequent event.
- Specified by:
destroy in interface org.linkedin.util.lifecycle.Destroyable
getTree
public java.util.Map<java.lang.String,TrackedNode<T>> getTree()
- Returns:
- the tree
track
public void track(NodeEventsListener<T> eventsListener)
throws java.lang.InterruptedException,
org.apache.zookeeper.KeeperException
- Throws:
java.lang.InterruptedException
org.apache.zookeeper.KeeperException
track
public void track()
throws java.lang.InterruptedException,
org.apache.zookeeper.KeeperException
- Throws:
java.lang.InterruptedException
org.apache.zookeeper.KeeperException
registerListener
public void registerListener(NodeEventsListener<T> eventsListener)
registerErrorListener
public void registerErrorListener(ErrorListener errorListener)