@InterfaceAudience.Private public abstract class ZooKeeperNodeTracker extends ZooKeeperListener
Utilizes the ZooKeeperListener
interface to get the necessary
ZooKeeper events related to the node.
This is the base class used by trackers in both the Master and RegionServers.
Modifier and Type | Field and Description |
---|---|
protected Abortable |
abortable
Used to abort if a fatal error occurs
|
protected static org.apache.commons.logging.Log |
LOG |
protected String |
node
Path of node being tracked
|
watcher
Constructor and Description |
---|
ZooKeeperNodeTracker(ZooKeeperWatcher watcher,
String node,
Abortable abortable)
Constructs a new ZK node tracker.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
blockUntilAvailable()
Gets the data of the node, blocking until the node is available.
|
byte[] |
blockUntilAvailable(long timeout,
boolean refresh)
Gets the data of the node, blocking until the node is available or the
specified timeout has elapsed.
|
boolean |
checkIfBaseNodeAvailable()
Checks if the baseznode set as per the property 'zookeeper.znode.parent'
exists.
|
byte[] |
getData(boolean refresh)
Gets the data of the node.
|
String |
getNode() |
void |
nodeCreated(String path)
Called when a new node has been created.
|
void |
nodeDataChanged(String path)
Called when an existing node has changed data.
|
void |
nodeDeleted(String path)
Called when a node has been deleted
|
void |
start()
Starts the tracking of the node in ZooKeeper.
|
void |
stop() |
String |
toString() |
getWatcher, nodeChildrenChanged
protected static final org.apache.commons.logging.Log LOG
protected final String node
protected final Abortable abortable
public ZooKeeperNodeTracker(ZooKeeperWatcher watcher, String node, Abortable abortable)
After construction, use start()
to kick off tracking.
watcher
- node
- abortable
- public void start()
Use blockUntilAvailable()
to block until the node is available
or getData(boolean)
to get the data of the node if it is available.
public void stop()
public byte[] blockUntilAvailable() throws InterruptedException
InterruptedException
- if the waiting thread is interruptedpublic byte[] blockUntilAvailable(long timeout, boolean refresh) throws InterruptedException
timeout
- maximum time to wait for the node data to be available,
n milliseconds. Pass 0 for no timeout.InterruptedException
- if the waiting thread is interruptedpublic byte[] getData(boolean refresh)
If the node is currently available, the most up-to-date known version of the data is returned. If the node is not currently available, null is returned.
refresh
- whether to refresh the data by calling ZK directly.public String getNode()
public void nodeCreated(String path)
ZooKeeperListener
nodeCreated
in class ZooKeeperListener
path
- full path of the new nodepublic void nodeDeleted(String path)
ZooKeeperListener
nodeDeleted
in class ZooKeeperListener
path
- full path of the deleted nodepublic void nodeDataChanged(String path)
ZooKeeperListener
nodeDataChanged
in class ZooKeeperListener
path
- full path of the updated nodepublic boolean checkIfBaseNodeAvailable()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.