org.apache.hadoop.hbase.zookeeper.ZKUtil.listChildrenAndWatchThem()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(186)

本文整理了Java中org.apache.hadoop.hbase.zookeeper.ZKUtil.listChildrenAndWatchThem()方法的一些代码示例,展示了ZKUtil.listChildrenAndWatchThem()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKUtil.listChildrenAndWatchThem()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.zookeeper.ZKUtil
类名称:ZKUtil
方法名:listChildrenAndWatchThem

ZKUtil.listChildrenAndWatchThem介绍

[英]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.
[中]列出指定znode的所有子节点,为子节点更改设置监视,并为每个子节点设置监视,以获得NodeCreated和NodeDeleted事件。

代码示例

代码示例来源:origin: apache/hbase

  1. break;
  2. List<String> children = listChildrenAndWatchThem(zkw, node);
  3. if (children == null) {
  4. continue;

代码示例来源:origin: apache/hbase

  1. /**
  2. * Read the list of children under the archive znode as table names and then sets those tables to
  3. * the list of tables that we should archive
  4. * @throws KeeperException if there is an unexpected zk exception
  5. */
  6. private void updateWatchedTables() throws KeeperException {
  7. // get the children and watch for new children
  8. LOG.debug("Updating watches on tables to archive.");
  9. // get the children and add watches for each of the children
  10. List<String> tables = ZKUtil.listChildrenAndWatchThem(watcher, archiveHFileZNode);
  11. LOG.debug("Starting archive for tables:" + tables);
  12. // if archiving is still enabled
  13. if (tables != null && tables.size() > 0) {
  14. getMonitor().setArchiveTables(tables);
  15. } else {
  16. LOG.debug("No tables to archive.");
  17. // only if we currently have a tracker, then clear the archive
  18. clearTables();
  19. }
  20. }

代码示例来源:origin: apache/hbase

  1. @Override
  2. public void nodeChildrenChanged(final String path) {
  3. if(path.equals(watcher.getZNodePaths().drainingZNode)) {
  4. try {
  5. final List<String> newNodes =
  6. ZKUtil.listChildrenAndWatchThem(watcher, watcher.getZNodePaths().drainingZNode);
  7. add(newNodes);
  8. } catch (KeeperException e) {
  9. abortable.abort("Unexpected zk exception getting RS nodes", e);
  10. } catch (IOException e) {
  11. abortable.abort("Unexpected zk exception getting RS nodes", e);
  12. }
  13. }
  14. }
  15. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Get a list of all the other region servers in this cluster and set a watch
  3. * @return a list of server nanes
  4. */
  5. private List<String> getRegisteredRegionServers(boolean watch) {
  6. List<String> result = null;
  7. try {
  8. if (watch) {
  9. result = ZKUtil.listChildrenAndWatchThem(this.zookeeper,
  10. this.zookeeper.getZNodePaths().rsZNode);
  11. } else {
  12. result = ZKUtil.listChildrenNoWatch(this.zookeeper, this.zookeeper.getZNodePaths().rsZNode);
  13. }
  14. } catch (KeeperException e) {
  15. this.abortable.abort("Get list of registered region servers", e);
  16. }
  17. return result;
  18. }
  19. }

代码示例来源:origin: apache/hbase

  1. /**
  2. * Starts the tracking of draining RegionServers.
  3. *
  4. * <p>All Draining RSs will be tracked after this method is called.
  5. *
  6. * @throws KeeperException
  7. */
  8. public void start() throws KeeperException, IOException {
  9. watcher.registerListener(this);
  10. // Add a ServerListener to check if a server is draining when it's added.
  11. serverManager.registerListener(new ServerListener() {
  12. @Override
  13. public void serverAdded(ServerName sn) {
  14. if (drainingServers.contains(sn)){
  15. serverManager.addServerToDrainList(sn);
  16. }
  17. }
  18. });
  19. List<String> servers =
  20. ZKUtil.listChildrenAndWatchThem(watcher, watcher.getZNodePaths().drainingZNode);
  21. add(servers);
  22. }

代码示例来源:origin: XiaoMi/themis

  1. protected void loadAliveClients() throws KeeperException, IOException {
  2. aliveClients.clear();
  3. aliveClients.addAll(ZKUtil.listChildrenAndWatchThem(watcher, aliveClientParentPath));
  4. }

代码示例来源:origin: co.cask.hbase/hbase

  1. /**
  2. * List this cluster's peers' IDs
  3. * @return list of all peers' identifiers
  4. */
  5. public List<String> listPeersIdsAndWatch() {
  6. List<String> ids = null;
  7. try {
  8. ids = ZKUtil.listChildrenAndWatchThem(this.zookeeper, this.peersZNode);
  9. } catch (KeeperException e) {
  10. this.abortable.abort("Cannot get the list of peers ", e);
  11. }
  12. return ids;
  13. }

代码示例来源:origin: harbby/presto-connectors

  1. /**
  2. * List all registered peer clusters and set a watch on their znodes.
  3. */
  4. @Override
  5. public List<String> getAllPeerIds() {
  6. List<String> ids = null;
  7. try {
  8. ids = ZKUtil.listChildrenAndWatchThem(this.zookeeper, this.peersZNode);
  9. } catch (KeeperException e) {
  10. this.abortable.abort("Cannot get the list of peers ", e);
  11. }
  12. return ids;
  13. }

代码示例来源:origin: harbby/presto-connectors

  1. /**
  2. * Get a list of all the other region servers in this cluster and set a watch
  3. * @return a list of server nanes
  4. */
  5. private List<String> getRegisteredRegionServers() {
  6. List<String> result = null;
  7. try {
  8. result = ZKUtil.listChildrenAndWatchThem(this.zookeeper, this.zookeeper.rsZNode);
  9. } catch (KeeperException e) {
  10. this.abortable.abort("Get list of registered region servers", e);
  11. }
  12. return result;
  13. }
  14. }

代码示例来源:origin: co.cask.hbase/hbase

  1. /**
  2. * Get a list of all the other region servers in this cluster
  3. * and set a watch
  4. * @return a list of server nanes
  5. */
  6. public List<String> getRegisteredRegionServers() {
  7. List<String> result = null;
  8. try {
  9. result = ZKUtil.listChildrenAndWatchThem(
  10. this.zookeeper, this.zookeeper.rsZNode);
  11. } catch (KeeperException e) {
  12. this.abortable.abort("Get list of registered region servers", e);
  13. }
  14. return result;
  15. }

代码示例来源:origin: co.cask.hbase/hbase

  1. /**
  2. * Starts the tracking of draining RegionServers.
  3. *
  4. * <p>All Draining RSs will be tracked after this method is called.
  5. *
  6. * @throws KeeperException
  7. */
  8. public void start() throws KeeperException, IOException {
  9. watcher.registerListener(this);
  10. List<String> servers =
  11. ZKUtil.listChildrenAndWatchThem(watcher, watcher.drainingZNode);
  12. add(servers);
  13. }

代码示例来源:origin: harbby/presto-connectors

  1. /**
  2. * Starts the tracking of draining RegionServers.
  3. *
  4. * <p>All Draining RSs will be tracked after this method is called.
  5. *
  6. * @throws KeeperException
  7. */
  8. public void start() throws KeeperException, IOException {
  9. watcher.registerListener(this);
  10. List<String> servers =
  11. ZKUtil.listChildrenAndWatchThem(watcher, watcher.drainingZNode);
  12. add(servers);
  13. }

代码示例来源:origin: co.cask.hbase/hbase

  1. /**
  2. * Starts the tracking of online RegionServers.
  3. *
  4. * <p>All RSs will be tracked after this method is called.
  5. *
  6. * @throws KeeperException
  7. * @throws IOException
  8. */
  9. public void start() throws KeeperException, IOException {
  10. watcher.registerListener(this);
  11. List<String> servers =
  12. ZKUtil.listChildrenAndWatchThem(watcher, watcher.rsZNode);
  13. add(servers);
  14. }

代码示例来源:origin: harbby/presto-connectors

  1. /**
  2. * Starts the tracking of online RegionServers.
  3. *
  4. * <p>All RSs will be tracked after this method is called.
  5. *
  6. * @throws KeeperException
  7. * @throws IOException
  8. */
  9. public void start() throws KeeperException, IOException {
  10. watcher.registerListener(this);
  11. List<String> servers =
  12. ZKUtil.listChildrenAndWatchThem(watcher, watcher.rsZNode);
  13. add(servers);
  14. }

代码示例来源:origin: co.cask.hbase/hbase

  1. @Override
  2. public void nodeChildrenChanged(String path) {
  3. if (path.equals(watcher.rsZNode)) {
  4. try {
  5. List<String> servers =
  6. ZKUtil.listChildrenAndWatchThem(watcher, watcher.rsZNode);
  7. add(servers);
  8. } catch (IOException e) {
  9. abortable.abort("Unexpected zk exception getting RS nodes", e);
  10. } catch (KeeperException e) {
  11. abortable.abort("Unexpected zk exception getting RS nodes", e);
  12. }
  13. }
  14. }

代码示例来源:origin: co.cask.hbase/hbase

  1. @Override
  2. public void nodeChildrenChanged(final String path) {
  3. if(path.equals(watcher.drainingZNode)) {
  4. try {
  5. final List<String> newNodes =
  6. ZKUtil.listChildrenAndWatchThem(watcher, watcher.drainingZNode);
  7. add(newNodes);
  8. } catch (KeeperException e) {
  9. abortable.abort("Unexpected zk exception getting RS nodes", e);
  10. } catch (IOException e) {
  11. abortable.abort("Unexpected zk exception getting RS nodes", e);
  12. }
  13. }
  14. }

代码示例来源:origin: harbby/presto-connectors

  1. @Override
  2. public void nodeChildrenChanged(final String path) {
  3. if(path.equals(watcher.drainingZNode)) {
  4. try {
  5. final List<String> newNodes =
  6. ZKUtil.listChildrenAndWatchThem(watcher, watcher.drainingZNode);
  7. add(newNodes);
  8. } catch (KeeperException e) {
  9. abortable.abort("Unexpected zk exception getting RS nodes", e);
  10. } catch (IOException e) {
  11. abortable.abort("Unexpected zk exception getting RS nodes", e);
  12. }
  13. }
  14. }
  15. }

代码示例来源:origin: harbby/presto-connectors

  1. @Override
  2. public void nodeChildrenChanged(String path) {
  3. if (path.equals(watcher.rsZNode)
  4. && !server.isAborted() && !server.isStopped()) {
  5. try {
  6. List<String> servers =
  7. ZKUtil.listChildrenAndWatchThem(watcher, watcher.rsZNode);
  8. add(servers);
  9. } catch (IOException e) {
  10. server.abort("Unexpected zk exception getting RS nodes", e);
  11. } catch (KeeperException e) {
  12. server.abort("Unexpected zk exception getting RS nodes", e);
  13. }
  14. }
  15. }

代码示例来源:origin: org.apache.hbase/hbase-replication

  1. /**
  2. * Get a list of all the other region servers in this cluster and set a watch
  3. * @return a list of server nanes
  4. */
  5. private List<String> getRegisteredRegionServers(boolean watch) {
  6. List<String> result = null;
  7. try {
  8. if (watch) {
  9. result = ZKUtil.listChildrenAndWatchThem(this.zookeeper,
  10. this.zookeeper.getZNodePaths().rsZNode);
  11. } else {
  12. result = ZKUtil.listChildrenNoWatch(this.zookeeper, this.zookeeper.getZNodePaths().rsZNode);
  13. }
  14. } catch (KeeperException e) {
  15. this.abortable.abort("Get list of registered region servers", e);
  16. }
  17. return result;
  18. }
  19. }

代码示例来源:origin: harbby/presto-connectors

  1. /**
  2. * Read the list of children under the archive znode as table names and then sets those tables to
  3. * the list of tables that we should archive
  4. * @throws KeeperException if there is an unexpected zk exception
  5. */
  6. private void updateWatchedTables() throws KeeperException {
  7. // get the children and watch for new children
  8. LOG.debug("Updating watches on tables to archive.");
  9. // get the children and add watches for each of the children
  10. List<String> tables = ZKUtil.listChildrenAndWatchThem(watcher, archiveHFileZNode);
  11. LOG.debug("Starting archive for tables:" + tables);
  12. // if archiving is still enabled
  13. if (tables != null && tables.size() > 0) {
  14. getMonitor().setArchiveTables(tables);
  15. } else {
  16. LOG.debug("No tables to archive.");
  17. // only if we currently have a tracker, then clear the archive
  18. clearTables();
  19. }
  20. }

相关文章