Java Code Examples for org.apache.hadoop.hbase.zookeeper.ZKUtil#listChildrenAndWatchThem()

The following examples show how to use org.apache.hadoop.hbase.zookeeper.ZKUtil#listChildrenAndWatchThem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrainingServerTracker.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: TableHFileArchiveTracker.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  }
}
 
Example 3
Source File: ReplicationTrackerZKImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}