org.apache.hadoop.hbase.zookeeper
Class ZKUtil

java.lang.Object
  extended by org.apache.hadoop.hbase.zookeeper.ZKUtil

public class ZKUtil
extends Object

Internal HBase utility class for ZooKeeper.

Contains only static methods and constants.

Methods all throw KeeperException if there is an unexpected zookeeper exception, so callers of these methods must handle appropriately. If ZK is required for the operation, the server will need to be aborted.


Nested Class Summary
static class ZKUtil.NodeAndData
          Simple class to hold a node path and node data.
 
Constructor Summary
ZKUtil()
           
 
Method Summary
static void applyClusterKeyToConf(org.apache.hadoop.conf.Configuration conf, String key)
          Apply the settings in the given key to the given configuration, this is used to communicate with distant clusters
static void asyncCreate(ZooKeeperWatcher zkw, String znode, byte[] data, org.apache.zookeeper.AsyncCallback.StringCallback cb, Object ctx)
          Async creates the specified node with the specified data.
static int checkExists(ZooKeeperWatcher zkw, String znode)
          Check if the specified node exists.
static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf, String ensemble, org.apache.zookeeper.Watcher watcher)
           
static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf, String ensemble, org.apache.zookeeper.Watcher watcher, String descriptor)
           
static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf, org.apache.zookeeper.Watcher watcher)
          Creates a new connection to ZooKeeper, pulling settings and ensemble config from the specified configuration object using methods from ZKConfig.
static void createAndFailSilent(ZooKeeperWatcher zkw, String znode)
          Creates the specified node, if the node does not exist.
static int createAndWatch(ZooKeeperWatcher zkw, String znode, byte[] data)
          Creates the specified node with the specified data and watches it.
static boolean createEphemeralNodeAndWatch(ZooKeeperWatcher zkw, String znode, byte[] data)
          Set the specified znode to be an ephemeral node carrying the specified data.
static boolean createNodeIfNotExistsAndWatch(ZooKeeperWatcher zkw, String znode, byte[] data)
          Creates the specified znode to be a persistent node carrying the specified data.
static void createSetData(ZooKeeperWatcher zkw, String znode, byte[] data)
          Set data into node creating node if it doesn't yet exist.
static void createWithParents(ZooKeeperWatcher zkw, String znode)
          Creates the specified node and all parent nodes required for it to exist.
static void deleteChildrenRecursively(ZooKeeperWatcher zkw, String node)
          Delete all the children of the specified node but not the node itself.
static void deleteNode(ZooKeeperWatcher zkw, String node)
          Delete the specified node.
static boolean deleteNode(ZooKeeperWatcher zkw, String node, int version)
          Delete the specified node with the specified version.
static void deleteNodeFailSilent(ZooKeeperWatcher zkw, String node)
          Deletes the specified node.
static void deleteNodeRecursively(ZooKeeperWatcher zkw, String node)
          Delete the specified node and all of it's children.
static String dump(ZooKeeperWatcher zkw)
           
static byte[] getData(ZooKeeperWatcher zkw, String znode)
          Get znode data.
static byte[] getDataAndWatch(ZooKeeperWatcher zkw, String znode)
          Get the data at the specified znode and set a watch.
static HServerAddress getDataAsAddress(ZooKeeperWatcher zkw, String znode)
          Get the data at the specified znode, deserialize it as an HServerAddress, and set a watch.
static byte[] getDataNoWatch(ZooKeeperWatcher zkw, String znode, org.apache.zookeeper.data.Stat stat)
          Get the data at the specified znode without setting a watch.
static String getNodeName(HServerInfo serverInfo)
          Get the unique node-name for the specified regionserver.
static String getNodeName(String path)
          Get the name of the current node from the specified fully-qualified path.
static int getNumberOfChildren(ZooKeeperWatcher zkw, String znode)
          Get the number of children of the specified node.
static String getParent(String node)
          Returns the full path of the immediate parent of the specified node.
static String[] getServerStats(String server)
          Gets the statistics from the given server.
static String[] getServerStats(String server, int timeout)
          Gets the statistics from the given server.
static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
          Get the key to the ZK ensemble for this configuration without adding a name at the end
static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf, String name)
          Get the key to the ZK ensemble for this configuration and append a name at the end
static String joinZNode(String prefix, String suffix)
          Join the prefix znode name with the suffix znode name to generate a proper full znode name.
static List<HServerAddress> listChildrenAndGetAsAddresses(ZooKeeperWatcher zkw, String znode)
          Lists the children of the specified znode, retrieving the data of each child as a server address.
static List<String> listChildrenAndWatchForNewChildren(ZooKeeperWatcher zkw, String znode)
          Lists the children znodes of the specified znode.
static List<String> listChildrenAndWatchThem(ZooKeeperWatcher zkw, String znode)
          List all the children of the specified znode, setting a watch for children changes and also setting a watch on every individual child in order to get the NodeCreated and NodeDeleted events.
static List<String> listChildrenNoWatch(ZooKeeperWatcher zkw, String znode)
          Lists the children of the specified znode without setting any watches.
static boolean nodeHasChildren(ZooKeeperWatcher zkw, String znode)
          Checks if the specified znode has any children.
static boolean setAddressAndWatch(ZooKeeperWatcher zkw, String znode, HServerAddress address)
          Set the specified znode to be an ephemeral node carrying the specified server address.
static void setData(ZooKeeperWatcher zkw, String znode, byte[] data)
          Sets the data of the existing znode to be the specified data.
static boolean setData(ZooKeeperWatcher zkw, String znode, byte[] data, int expectedVersion)
          Sets the data of the existing znode to be the specified data.
static String[] transformClusterKey(String key)
          Separate the given key into the three configurations it should contain: hbase.zookeeper.quorum, hbase.zookeeper.client.port and zookeeper.znode.parent
static void updateExistingNodeData(ZooKeeperWatcher zkw, String znode, byte[] data, int expectedVersion)
          Update the data of an existing node with the expected version to have the specified data.
static boolean watchAndCheckExists(ZooKeeperWatcher zkw, String znode)
          Watch the specified znode for delete/create/change events.
static List<ZKUtil.NodeAndData> watchAndGetNewChildren(ZooKeeperWatcher zkw, String baseNode)
          Atomically add watches and read data from all unwatched unassigned nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZKUtil

public ZKUtil()
Method Detail

connect

public static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf,
                                                     org.apache.zookeeper.Watcher watcher)
                                              throws IOException
Creates a new connection to ZooKeeper, pulling settings and ensemble config from the specified configuration object using methods from ZKConfig. Sets the connection status monitoring watcher to the specified watcher.

Parameters:
conf - configuration to pull ensemble and other settings from
watcher - watcher to monitor connection changes
Returns:
connection to zookeeper
Throws:
IOException - if unable to connect to zk or config problem

connect

public static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf,
                                                     String ensemble,
                                                     org.apache.zookeeper.Watcher watcher)
                                              throws IOException
Throws:
IOException

connect

public static org.apache.zookeeper.ZooKeeper connect(org.apache.hadoop.conf.Configuration conf,
                                                     String ensemble,
                                                     org.apache.zookeeper.Watcher watcher,
                                                     String descriptor)
                                              throws IOException
Throws:
IOException

joinZNode

public static String joinZNode(String prefix,
                               String suffix)
Join the prefix znode name with the suffix znode name to generate a proper full znode name. Assumes prefix does not end with slash and suffix does not begin with it.

Parameters:
prefix - beginning of znode name
suffix - ending of znode name
Returns:
result of properly joining prefix with suffix

getParent

public static String getParent(String node)
Returns the full path of the immediate parent of the specified node.

Parameters:
node - path to get parent of
Returns:
parent of path, null if passed the root node or an invalid node

getNodeName

public static String getNodeName(HServerInfo serverInfo)
Get the unique node-name for the specified regionserver. Used when a server puts up an ephemeral node for itself and needs to use a unique name.

Parameters:
serverInfo - server information
Returns:
unique, zookeeper-safe znode path for the server instance

getNodeName

public static String getNodeName(String path)
Get the name of the current node from the specified fully-qualified path.

Parameters:
path - fully-qualified path
Returns:
name of the current node

getZooKeeperClusterKey

public static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf)
Get the key to the ZK ensemble for this configuration without adding a name at the end

Parameters:
conf - Configuration to use to build the key
Returns:
ensemble key without a name

getZooKeeperClusterKey

public static String getZooKeeperClusterKey(org.apache.hadoop.conf.Configuration conf,
                                            String name)
Get the key to the ZK ensemble for this configuration and append a name at the end

Parameters:
conf - Configuration to use to build the key
name - Name that should be appended at the end if not empty or null
Returns:
ensemble key with a name (if any)

applyClusterKeyToConf

public static void applyClusterKeyToConf(org.apache.hadoop.conf.Configuration conf,
                                         String key)
                                  throws IOException
Apply the settings in the given key to the given configuration, this is used to communicate with distant clusters

Parameters:
conf - configuration object to configure
key - string that contains the 3 required configuratins
Throws:
IOException

transformClusterKey

public static String[] transformClusterKey(String key)
                                    throws IOException
Separate the given key into the three configurations it should contain: hbase.zookeeper.quorum, hbase.zookeeper.client.port and zookeeper.znode.parent

Parameters:
key -
Returns:
the three configuration in the described order
Throws:
IOException

watchAndCheckExists

public static boolean watchAndCheckExists(ZooKeeperWatcher zkw,
                                          String znode)
                                   throws org.apache.zookeeper.KeeperException
Watch the specified znode for delete/create/change events. The watcher is set whether or not the node exists. If the node already exists, the method returns true. If the node does not exist, the method returns false.

Parameters:
zkw - zk reference
znode - path of node to watch
Returns:
true if znode exists, false if does not exist or error
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

checkExists

public static int checkExists(ZooKeeperWatcher zkw,
                              String znode)
                       throws org.apache.zookeeper.KeeperException
Check if the specified node exists. Sets no watches. Returns true if node exists, false if not. Returns an exception if there is an unexpected zookeeper exception.

Parameters:
zkw - zk reference
znode - path of node to watch
Returns:
version of the node if it exists, -1 if does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

listChildrenAndWatchForNewChildren

public static List<String> listChildrenAndWatchForNewChildren(ZooKeeperWatcher zkw,
                                                              String znode)
                                                       throws org.apache.zookeeper.KeeperException
Lists the children znodes of the specified znode. Also sets a watch on the specified znode which will capture a NodeDeleted event on the specified znode as well as NodeChildrenChanged if any children of the specified znode are created or deleted. Returns null if the specified node does not exist. Otherwise returns a list of children of the specified node. If the node exists but it has no children, an empty list will be returned.

Parameters:
zkw - zk reference
znode - path of node to list and watch children of
Returns:
list of children of the specified node, an empty list if the node exists but has no children, and null if the node does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

listChildrenAndWatchThem

public static List<String> listChildrenAndWatchThem(ZooKeeperWatcher zkw,
                                                    String znode)
                                             throws org.apache.zookeeper.KeeperException
List all the children of the specified znode, setting a watch for children changes and also setting a watch on every individual child in order to get the NodeCreated and NodeDeleted events.

Parameters:
zkw - zookeeper reference
znode - node to get children of and watch
Returns:
list of znode names, null if the node doesn't exist
Throws:
org.apache.zookeeper.KeeperException

listChildrenAndGetAsAddresses

public static List<HServerAddress> listChildrenAndGetAsAddresses(ZooKeeperWatcher zkw,
                                                                 String znode)
                                                          throws org.apache.zookeeper.KeeperException
Lists the children of the specified znode, retrieving the data of each child as a server address. Used to list the currently online regionservers and their addresses. Sets no watches at all, this method is best effort. Returns an empty list if the node has no children. Returns null if the parent node itself does not exist.

Parameters:
zkw - zookeeper reference
znode - node to get children of as addresses
Returns:
list of data of children of specified znode, empty if no children, null if parent does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

listChildrenNoWatch

public static List<String> listChildrenNoWatch(ZooKeeperWatcher zkw,
                                               String znode)
                                        throws org.apache.zookeeper.KeeperException
Lists the children of the specified znode without setting any watches. Used to list the currently online regionservers and their addresses. Sets no watches at all, this method is best effort. Returns an empty list if the node has no children. Returns null if the parent node itself does not exist.

Parameters:
zkw - zookeeper reference
znode - node to get children of as addresses
Returns:
list of data of children of specified znode, empty if no children, null if parent does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

watchAndGetNewChildren

public static List<ZKUtil.NodeAndData> watchAndGetNewChildren(ZooKeeperWatcher zkw,
                                                              String baseNode)
                                                       throws org.apache.zookeeper.KeeperException
Atomically add watches and read data from all unwatched unassigned nodes.

This works because master is the only person deleting nodes.

Throws:
org.apache.zookeeper.KeeperException

nodeHasChildren

public static boolean nodeHasChildren(ZooKeeperWatcher zkw,
                                      String znode)
                               throws org.apache.zookeeper.KeeperException
Checks if the specified znode has any children. Sets no watches. Returns true if the node exists and has children. Returns false if the node does not exist or if the node does not have any children. Used during master initialization to determine if the master is a failed-over-to master or the first master during initial cluster startup. If the directory for regionserver ephemeral nodes is empty then this is a cluster startup, if not then it is not cluster startup.

Parameters:
zkw - zk reference
znode - path of node to check for children of
Returns:
true if node has children, false if not or node does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

getNumberOfChildren

public static int getNumberOfChildren(ZooKeeperWatcher zkw,
                                      String znode)
                               throws org.apache.zookeeper.KeeperException
Get the number of children of the specified node. If the node does not exist or has no children, returns 0. Sets no watches at all.

Parameters:
zkw - zk reference
znode - path of node to count children of
Returns:
number of children of specified node, 0 if none or parent does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

getData

public static byte[] getData(ZooKeeperWatcher zkw,
                             String znode)
                      throws org.apache.zookeeper.KeeperException
Get znode data. Does not set a watcher.

Returns:
ZNode data
Throws:
org.apache.zookeeper.KeeperException

getDataAndWatch

public static byte[] getDataAndWatch(ZooKeeperWatcher zkw,
                                     String znode)
                              throws org.apache.zookeeper.KeeperException
Get the data at the specified znode and set a watch. Returns the data and sets a watch if the node exists. Returns null and no watch is set if the node does not exist or there is an exception.

Parameters:
zkw - zk reference
znode - path of node
Returns:
data of the specified znode, or null
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

getDataNoWatch

public static byte[] getDataNoWatch(ZooKeeperWatcher zkw,
                                    String znode,
                                    org.apache.zookeeper.data.Stat stat)
                             throws org.apache.zookeeper.KeeperException
Get the data at the specified znode without setting a watch. Returns the data if the node exists. Returns null if the node does not exist. Sets the stats of the node in the passed Stat object. Pass a null stat if not interested.

Parameters:
zkw - zk reference
znode - path of node
stat - node status to set if node exists
Returns:
data of the specified znode, or null if node does not exist
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

getDataAsAddress

public static HServerAddress getDataAsAddress(ZooKeeperWatcher zkw,
                                              String znode)
                                       throws org.apache.zookeeper.KeeperException
Get the data at the specified znode, deserialize it as an HServerAddress, and set a watch. Returns the data as a server address and sets a watch if the node exists. Returns null and no watch is set if the node does not exist or there is an exception.

Parameters:
zkw - zk reference
znode - path of node
Returns:
data of the specified node as a server address, or null
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

updateExistingNodeData

public static void updateExistingNodeData(ZooKeeperWatcher zkw,
                                          String znode,
                                          byte[] data,
                                          int expectedVersion)
                                   throws org.apache.zookeeper.KeeperException
Update the data of an existing node with the expected version to have the specified data. Throws an exception if there is a version mismatch or some other problem. Sets no watches under any conditions.

Parameters:
zkw - zk reference
znode -
data -
expectedVersion -
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
KeeperException.BadVersionException - if version mismatch

setAddressAndWatch

public static boolean setAddressAndWatch(ZooKeeperWatcher zkw,
                                         String znode,
                                         HServerAddress address)
                                  throws org.apache.zookeeper.KeeperException
Set the specified znode to be an ephemeral node carrying the specified server address. Used by masters for their ephemeral node and regionservers for their ephemeral node. If the node is created successfully, a watcher is also set on the node. If the node is not created successfully because it already exists, this method will also set a watcher on the node. If there is another problem, a KeeperException will be thrown.

Parameters:
zkw - zk reference
znode - path of node
address - server address
Returns:
true if address set, false if not, watch set in both cases
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

setData

public static boolean setData(ZooKeeperWatcher zkw,
                              String znode,
                              byte[] data,
                              int expectedVersion)
                       throws org.apache.zookeeper.KeeperException,
                              org.apache.zookeeper.KeeperException.NoNodeException
Sets the data of the existing znode to be the specified data. Ensures that the current data has the specified expected version.

If the node does not exist, a KeeperException.NoNodeException will be thrown.

If their is a version mismatch, method returns null.

No watches are set but setting data will trigger other watchers of this node.

If there is another problem, a KeeperException will be thrown.

Parameters:
zkw - zk reference
znode - path of node
data - data to set for node
expectedVersion - version expected when setting data
Returns:
true if data set, false if version mismatch
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
org.apache.zookeeper.KeeperException.NoNodeException

createSetData

public static void createSetData(ZooKeeperWatcher zkw,
                                 String znode,
                                 byte[] data)
                          throws org.apache.zookeeper.KeeperException
Set data into node creating node if it doesn't yet exist. Does not set watch.

Parameters:
zkw - zk reference
znode - path of node
data - data to set for node
Throws:
org.apache.zookeeper.KeeperException

setData

public static void setData(ZooKeeperWatcher zkw,
                           String znode,
                           byte[] data)
                    throws org.apache.zookeeper.KeeperException,
                           org.apache.zookeeper.KeeperException.NoNodeException
Sets the data of the existing znode to be the specified data. The node must exist but no checks are done on the existing data or version.

If the node does not exist, a KeeperException.NoNodeException will be thrown.

No watches are set but setting data will trigger other watchers of this node.

If there is another problem, a KeeperException will be thrown.

Parameters:
zkw - zk reference
znode - path of node
data - data to set for node
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
org.apache.zookeeper.KeeperException.NoNodeException

createEphemeralNodeAndWatch

public static boolean createEphemeralNodeAndWatch(ZooKeeperWatcher zkw,
                                                  String znode,
                                                  byte[] data)
                                           throws org.apache.zookeeper.KeeperException
Set the specified znode to be an ephemeral node carrying the specified data. If the node is created successfully, a watcher is also set on the node. If the node is not created successfully because it already exists, this method will also set a watcher on the node. If there is another problem, a KeeperException will be thrown.

Parameters:
zkw - zk reference
znode - path of node
data - data of node
Returns:
true if node created, false if not, watch set in both cases
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

createNodeIfNotExistsAndWatch

public static boolean createNodeIfNotExistsAndWatch(ZooKeeperWatcher zkw,
                                                    String znode,
                                                    byte[] data)
                                             throws org.apache.zookeeper.KeeperException
Creates the specified znode to be a persistent node carrying the specified data. Returns true if the node was successfully created, false if the node already existed. If the node is created successfully, a watcher is also set on the node. If the node is not created successfully because it already exists, this method will also set a watcher on the node but return false. If there is another problem, a KeeperException will be thrown.

Parameters:
zkw - zk reference
znode - path of node
data - data of node
Returns:
true if node created, false if not, watch set in both cases
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

createAndWatch

public static int createAndWatch(ZooKeeperWatcher zkw,
                                 String znode,
                                 byte[] data)
                          throws org.apache.zookeeper.KeeperException,
                                 org.apache.zookeeper.KeeperException.NodeExistsException
Creates the specified node with the specified data and watches it.

Throws an exception if the node already exists.

The node created is persistent and open access.

Returns the version number of the created node if successful.

Parameters:
zkw - zk reference
znode - path of node to create
data - data of node to create
Returns:
version of node created
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
KeeperException.NodeExistsException - if node already exists

asyncCreate

public static void asyncCreate(ZooKeeperWatcher zkw,
                               String znode,
                               byte[] data,
                               org.apache.zookeeper.AsyncCallback.StringCallback cb,
                               Object ctx)
                        throws org.apache.zookeeper.KeeperException,
                               org.apache.zookeeper.KeeperException.NodeExistsException
Async creates the specified node with the specified data.

Throws an exception if the node already exists.

The node created is persistent and open access.

Parameters:
zkw - zk reference
znode - path of node to create
data - data of node to create
cb -
ctx -
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
KeeperException.NodeExistsException - if node already exists

createAndFailSilent

public static void createAndFailSilent(ZooKeeperWatcher zkw,
                                       String znode)
                                throws org.apache.zookeeper.KeeperException
Creates the specified node, if the node does not exist. Does not set a watch and fails silently if the node already exists. The node created is persistent and open access.

Parameters:
zkw - zk reference
znode - path of node
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

createWithParents

public static void createWithParents(ZooKeeperWatcher zkw,
                                     String znode)
                              throws org.apache.zookeeper.KeeperException
Creates the specified node and all parent nodes required for it to exist. No watches are set and no errors are thrown if the node already exists. The nodes created are persistent and open access.

Parameters:
zkw - zk reference
znode - path of node
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception

deleteNode

public static void deleteNode(ZooKeeperWatcher zkw,
                              String node)
                       throws org.apache.zookeeper.KeeperException
Delete the specified node. Sets no watches. Throws all exceptions.

Throws:
org.apache.zookeeper.KeeperException

deleteNode

public static boolean deleteNode(ZooKeeperWatcher zkw,
                                 String node,
                                 int version)
                          throws org.apache.zookeeper.KeeperException
Delete the specified node with the specified version. Sets no watches. Throws all exceptions.

Throws:
org.apache.zookeeper.KeeperException

deleteNodeFailSilent

public static void deleteNodeFailSilent(ZooKeeperWatcher zkw,
                                        String node)
                                 throws org.apache.zookeeper.KeeperException
Deletes the specified node. Fails silent if the node does not exist.

Parameters:
zkw -
node -
Throws:
org.apache.zookeeper.KeeperException

deleteNodeRecursively

public static void deleteNodeRecursively(ZooKeeperWatcher zkw,
                                         String node)
                                  throws org.apache.zookeeper.KeeperException
Delete the specified node and all of it's children. Sets no watches. Throws all exceptions besides dealing with deletion of children.

Throws:
org.apache.zookeeper.KeeperException

deleteChildrenRecursively

public static void deleteChildrenRecursively(ZooKeeperWatcher zkw,
                                             String node)
                                      throws org.apache.zookeeper.KeeperException
Delete all the children of the specified node but not the node itself. Sets no watches. Throws all exceptions besides dealing with deletion of children.

Throws:
org.apache.zookeeper.KeeperException

dump

public static String dump(ZooKeeperWatcher zkw)
Returns:
String dump of everything in ZooKeeper.

getServerStats

public static String[] getServerStats(String server)
                               throws IOException
Gets the statistics from the given server. Uses a 1 minute timeout.

Parameters:
server - The server to get the statistics from.
Returns:
The array of response strings.
Throws:
IOException - When the socket communication fails.

getServerStats

public static String[] getServerStats(String server,
                                      int timeout)
                               throws IOException
Gets the statistics from the given server.

Parameters:
server - The server to get the statistics from.
timeout - The socket timeout to use.
Returns:
The array of response strings.
Throws:
IOException - When the socket communication fails.


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