Class ZKNodeTracker
java.lang.Object
org.apache.hadoop.hbase.zookeeper.ZKListener
org.apache.hadoop.hbase.zookeeper.ZKNodeTracker
- Direct Known Subclasses:
ClusterStatusTracker
,MasterAddressTracker
Tracks the availability and value of a single ZooKeeper node.
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.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Abortable
Used to abort if a fatal error occursprivate byte[]
Data of the node being trackedprotected static final org.slf4j.Logger
protected final String
Path of node being trackedprivate boolean
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
watcher
-
Constructor Summary
ConstructorDescriptionZKNodeTracker
(ZKWatcher watcher, String node, Abortable abortable) Constructs a new ZK node tracker. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
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
Checks if the baseznode set as per the property 'zookeeper.znode.parent' exists.byte[]
getData
(boolean refresh) Gets the data of the node.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 deletedprotected void
Called after start is called.void
start()
Starts the tracking of the node in ZooKeeper.void
stop()
toString()
Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZKListener
getWatcher, nodeChildrenChanged
-
Field Details
-
LOG
-
node
Path of node being tracked -
data
Data of the node being tracked -
abortable
Used to abort if a fatal error occurs -
stopped
-
-
Constructor Details
-
Method Details
-
start
Starts the tracking of the node in ZooKeeper. UseblockUntilAvailable()
to block until the node is available orgetData(boolean)
to get the data of the node if it is available. -
postStart
Called after start is called. Sub classes could implement this method to load more data on zk. -
stop
-
blockUntilAvailable
Gets the data of the node, blocking until the node is available.- Returns:
- data of the node
- Throws:
InterruptedException
- if the waiting thread is interrupted
-
blockUntilAvailable
Gets the data of the node, blocking until the node is available or the specified timeout has elapsed.- Parameters:
timeout
- maximum time to wait for the node data to be available, n milliseconds. Pass 0 for no timeout.- Returns:
- data of the node
- Throws:
InterruptedException
- if the waiting thread is interrupted
-
getData
Gets the data of the node.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.
- Parameters:
refresh
- whether to refresh the data by calling ZK directly.- Returns:
- data of the node, null if unavailable
-
getNode
-
nodeCreated
Description copied from class:ZKListener
Called when a new node has been created.- Overrides:
nodeCreated
in classZKListener
- Parameters:
path
- full path of the new node
-
nodeDeleted
Description copied from class:ZKListener
Called when a node has been deleted- Overrides:
nodeDeleted
in classZKListener
- Parameters:
path
- full path of the deleted node
-
nodeDataChanged
Description copied from class:ZKListener
Called when an existing node has changed data.- Overrides:
nodeDataChanged
in classZKListener
- Parameters:
path
- full path of the updated node
-
checkIfBaseNodeAvailable
Checks if the baseznode set as per the property 'zookeeper.znode.parent' exists.- Returns:
- true if baseznode exists. false if doesnot exists.
-
toString
-