org.apache.hadoop.hbase.zookeeper
Class ZooKeeperNodeTracker

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
      extended by org.apache.hadoop.hbase.zookeeper.ZooKeeperNodeTracker
Direct Known Subclasses:
MasterAddressTracker, MetaRegionTracker, ReplicationPeer.PeerStateTracker

@InterfaceAudience.Public
@InterfaceStability.Evolving
public abstract class ZooKeeperNodeTracker
extends ZooKeeperListener

Tracks the availability and value of a single ZooKeeper node.

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.


Field Summary
protected  Abortable abortable
          Used to abort if a fatal error occurs
protected  String node
          Path of node being tracked
 
Fields inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
watcher
 
Constructor Summary
ZooKeeperNodeTracker(ZooKeeperWatcher watcher, String node, Abortable abortable)
          Constructs a new ZK node tracker.
 
Method Summary
 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()
           
 
Methods inherited from class org.apache.hadoop.hbase.zookeeper.ZooKeeperListener
nodeChildrenChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

protected final String node
Path of node being tracked


abortable

protected final Abortable abortable
Used to abort if a fatal error occurs

Constructor Detail

ZooKeeperNodeTracker

public ZooKeeperNodeTracker(ZooKeeperWatcher watcher,
                            String node,
                            Abortable abortable)
Constructs a new ZK node tracker.

After construction, use start() to kick off tracking.

Parameters:
watcher -
node -
abortable -
Method Detail

start

public void start()
Starts the tracking of the node in ZooKeeper.

Use blockUntilAvailable() to block until the node is available or getData(boolean) to get the data of the node if it is available.


stop

public void stop()

blockUntilAvailable

public byte[] blockUntilAvailable()
                           throws InterruptedException
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

public byte[] blockUntilAvailable(long timeout,
                                  boolean refresh)
                           throws InterruptedException
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

public byte[] getData(boolean refresh)
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

public String getNode()

nodeCreated

public void nodeCreated(String path)
Description copied from class: ZooKeeperListener
Called when a new node has been created.

Overrides:
nodeCreated in class ZooKeeperListener
Parameters:
path - full path of the new node

nodeDeleted

public void nodeDeleted(String path)
Description copied from class: ZooKeeperListener
Called when a node has been deleted

Overrides:
nodeDeleted in class ZooKeeperListener
Parameters:
path - full path of the deleted node

nodeDataChanged

public void nodeDataChanged(String path)
Description copied from class: ZooKeeperListener
Called when an existing node has changed data.

Overrides:
nodeDataChanged in class ZooKeeperListener
Parameters:
path - full path of the updated node

checkIfBaseNodeAvailable

public boolean checkIfBaseNodeAvailable()
Checks if the baseznode set as per the property 'zookeeper.znode.parent' exists.

Returns:
true if baseznode exists. false if doesnot exists.


Copyright © 2013 The Apache Software Foundation. All Rights Reserved.