下面列出了org.apache.hadoop.hbase.zookeeper.ZKUtil#listChildrenAndWatchThem ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Starts the tracking of draining RegionServers.
*
* <p>All Draining RSs will be tracked after this method is called.
*
* @throws KeeperException
*/
public void start() throws KeeperException, IOException {
watcher.registerListener(this);
// Add a ServerListener to check if a server is draining when it's added.
serverManager.registerListener(new ServerListener() {
@Override
public void serverAdded(ServerName sn) {
if (drainingServers.contains(sn)){
serverManager.addServerToDrainList(sn);
}
}
});
List<String> servers =
ZKUtil.listChildrenAndWatchThem(watcher, watcher.getZNodePaths().drainingZNode);
add(servers);
}
/**
* Read the list of children under the archive znode as table names and then sets those tables to
* the list of tables that we should archive
* @throws KeeperException if there is an unexpected zk exception
*/
private void updateWatchedTables() throws KeeperException {
// get the children and watch for new children
LOG.debug("Updating watches on tables to archive.");
// get the children and add watches for each of the children
List<String> tables = ZKUtil.listChildrenAndWatchThem(watcher, archiveHFileZNode);
LOG.debug("Starting archive for tables:" + tables);
// if archiving is still enabled
if (tables != null && tables.size() > 0) {
getMonitor().setArchiveTables(tables);
} else {
LOG.debug("No tables to archive.");
// only if we currently have a tracker, then clear the archive
clearTables();
}
}
/**
* Get a list of all the other region servers in this cluster and set a watch
* @return a list of server nanes
*/
private List<String> getRegisteredRegionServers(boolean watch) {
List<String> result = null;
try {
if (watch) {
result = ZKUtil.listChildrenAndWatchThem(this.zookeeper,
this.zookeeper.getZNodePaths().rsZNode);
} else {
result = ZKUtil.listChildrenNoWatch(this.zookeeper, this.zookeeper.getZNodePaths().rsZNode);
}
} catch (KeeperException e) {
this.abortable.abort("Get list of registered region servers", e);
}
return result;
}