@InterfaceAudience.Private public abstract class ZKNodeTracker extends ZKListener
Utilizes the ZKListener
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
|
private byte[] |
data
Data of the node being tracked
|
protected static org.slf4j.Logger |
LOG |
protected String |
node
Path of node being tracked
|
private boolean |
stopped |
watcher
Constructor and Description |
---|
ZKNodeTracker(ZKWatcher 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.slf4j.Logger LOG
private byte[] data
private boolean stopped
public ZKNodeTracker(ZKWatcher watcher, String node, Abortable abortable)
After construction, use start()
to kick off tracking.
watcher
- reference to the ZKWatcher
which also contains configuration and
constantsnode
- path of the node being trackedabortable
- used to abort if a fatal error occurspublic 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 void nodeCreated(String path)
ZKListener
nodeCreated
in class ZKListener
path
- full path of the new nodepublic void nodeDeleted(String path)
ZKListener
nodeDeleted
in class ZKListener
path
- full path of the deleted nodepublic void nodeDataChanged(String path)
ZKListener
nodeDataChanged
in class ZKListener
path
- full path of the updated nodepublic boolean checkIfBaseNodeAvailable()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.