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

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

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

ZKUtil.getDataAndWatch介绍

[英]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.
[中]在指定的znode获取数据并设置一个手表。如果节点存在,则返回数据并设置监视。返回null,如果节点不存在或存在异常,则不设置监视。

代码示例

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

  1. /**
  2. * Gets the data of the node.
  3. *
  4. * <p>If the node is currently available, the most up-to-date known version of
  5. * the data is returned. If the node is not currently available, null is
  6. * returned.
  7. * @param refresh whether to refresh the data by calling ZK directly.
  8. * @return data of the node, null if unavailable
  9. */
  10. public synchronized byte [] getData(boolean refresh) {
  11. if (refresh) {
  12. try {
  13. this.data = ZKUtil.getDataAndWatch(watcher, node);
  14. } catch(KeeperException e) {
  15. abortable.abort("Unexpected exception handling getData", e);
  16. }
  17. }
  18. return this.data;
  19. }

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

  1. @Override
  2. public void nodeCreated(String path) {
  3. if (!validate(path)) {
  4. return;
  5. }
  6. try {
  7. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  8. upsertQueue(path, data);
  9. } catch (KeeperException e) {
  10. LOG.warn("Unexpected exception handling nodeCreated event", e);
  11. }
  12. }

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

  1. @Override
  2. public void run() {
  3. // update cache on an existing table node
  4. String entry = ZKUtil.getNodeName(path);
  5. try {
  6. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  7. refreshAuthManager(entry, data);
  8. } catch (KeeperException ke) {
  9. LOG.error("Error reading data from zookeeper for node " + entry, ke);
  10. // only option is to abort
  11. watcher.abort("ZooKeeper error getting data for node " + entry, ke);
  12. } catch (IOException ioe) {
  13. LOG.error("Error reading permissions writables", ioe);
  14. }
  15. }
  16. });

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

  1. @Override
  2. public synchronized void nodeCreated(String path) {
  3. if (!path.equals(node)) {
  4. return;
  5. }
  6. try {
  7. byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  8. if (data != null) {
  9. this.data = data;
  10. notifyAll();
  11. } else {
  12. nodeDeleted(path);
  13. }
  14. } catch(KeeperException e) {
  15. abortable.abort("Unexpected exception handling nodeCreated event", e);
  16. }
  17. }

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

  1. @Override
  2. public void nodeDataChanged(String path) {
  3. if (path.equals(labelZnode) || path.equals(userAuthsZnode)) {
  4. try {
  5. watcher.sync(path);
  6. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  7. if (path.equals(labelZnode)) {
  8. refreshVisibilityLabelsCache(data);
  9. } else {
  10. refreshUserAuthsCache(data);
  11. }
  12. } catch (KeeperException ke) {
  13. LOG.error("Error reading data from zookeeper for node " + path, ke);
  14. // only option is to abort
  15. watcher.abort("ZooKeeper error getting data for node " + path, ke);
  16. }
  17. }
  18. }

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

  1. public void start() throws KeeperException {
  2. watcher.registerListener(this);
  3. ZKUtil.createWithParents(watcher, labelZnode);
  4. ZKUtil.createWithParents(watcher, userAuthsZnode);
  5. byte[] data = ZKUtil.getDataAndWatch(watcher, labelZnode);
  6. if (data != null && data.length > 0) {
  7. refreshVisibilityLabelsCache(data);
  8. }
  9. data = ZKUtil.getDataAndWatch(watcher, userAuthsZnode);
  10. if (data != null && data.length > 0) {
  11. refreshUserAuthsCache(data);
  12. }
  13. }

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

  1. try {
  2. this.data = ZKUtil.getDataAndWatch(watcher, node);
  3. } catch(KeeperException e) {
  4. try {
  5. this.data = ZKUtil.getDataAndWatch(watcher, node);
  6. } catch (KeeperException e) {
  7. LOG.warn("Unexpected exception handling blockUntilAvailable", e);

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

  1. for (String node : nodes) {
  2. String nodePath = ZNodePaths.joinZNode(baseNode, node);
  3. byte[] data = ZKUtil.getDataAndWatch(zkw, nodePath);
  4. newNodes.add(new NodeAndData(nodePath, data));

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

  1. @Override
  2. public void nodeDataChanged(String path) {
  3. if (keysParentZNode.equals(ZKUtil.getParent(path))) {
  4. try {
  5. byte[] data = ZKUtil.getDataAndWatch(watcher, path);
  6. if (data == null || data.length == 0) {
  7. LOG.debug("Ignoring empty node "+path);
  8. return;
  9. }
  10. AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
  11. new AuthenticationKey());
  12. secretManager.addKey(key);
  13. } catch (KeeperException ke) {
  14. LOG.error(HBaseMarkers.FATAL, "Error reading data from zookeeper", ke);
  15. watcher.abort("Error reading updated key znode "+path, ke);
  16. } catch (IOException ioe) {
  17. LOG.error(HBaseMarkers.FATAL, "Error reading key writables", ioe);
  18. watcher.abort("Error reading key writables from znode "+path, ioe);
  19. }
  20. }
  21. }

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

  1. /**
  2. * Starts the tracking of the node in ZooKeeper.
  3. *
  4. * <p>Use {@link #blockUntilAvailable()} to block until the node is available
  5. * or {@link #getData(boolean)} to get the data of the node if it is available.
  6. */
  7. public synchronized void start() {
  8. this.watcher.registerListener(this);
  9. try {
  10. if(ZKUtil.watchAndCheckExists(watcher, node)) {
  11. byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  12. if(data != null) {
  13. this.data = data;
  14. } else {
  15. // It existed but now does not, try again to ensure a watch is set
  16. LOG.debug("Try starting again because there is no data from " + node);
  17. start();
  18. }
  19. }
  20. } catch (KeeperException e) {
  21. abortable.abort("Unexpected exception during initialization, aborting", e);
  22. }
  23. }

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

  1. private void watchAndCheckExists(String node) {
  2. try {
  3. if (ZKUtil.watchAndCheckExists(watcher, node)) {
  4. byte[] data = ZKUtil.getDataAndWatch(watcher, node);
  5. if (data != null) {
  6. // put the data into queue
  7. upsertQueue(node, data);
  8. } else {
  9. // It existed but now does not, should has been tracked by our watcher, ignore
  10. LOG.debug("Found no data from " + node);
  11. watchAndCheckExists(node);
  12. }
  13. } else {
  14. // cleanup stale ZNodes on client ZK to avoid invalid requests to server
  15. ZKUtil.deleteNodeFailSilent(clientZkWatcher, node);
  16. }
  17. } catch (KeeperException e) {
  18. server.abort("Unexpected exception during initialization, aborting", e);
  19. }
  20. }

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

  1. byte[] currentId = ZKUtil.getDataAndWatch(watcher, leaderZNode);
  2. if (currentId != null && Bytes.equals(currentId, nodeId)) {

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

  1. ZKUtil.getDataAndWatch(this.watcher, this.watcher.getZNodePaths().masterAddressZNode);
  2. if (bytes == null) {
  3. msg = ("A master was detected, but went down before its address " +

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

  1. /**
  2. * Reinstall watcher because watcher only fire once though we're only interested in nodeDeleted
  3. * event we need to register the watcher in case other event happens
  4. */
  5. private void registerWatcher(String path) {
  6. String parentPath = path.substring(0, path.lastIndexOf('/'));
  7. if (!this.watcher.recoveringRegionsZNode.equalsIgnoreCase(parentPath)) {
  8. return;
  9. }
  10. try {
  11. ZKUtil.getDataAndWatch(watcher, path);
  12. } catch (KeeperException e) {
  13. LOG.warn("Can't register watcher on znode " + path, e);
  14. }
  15. }
  16. }

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

  1. /**
  2. * Gets the data of the node.
  3. *
  4. * <p>If the node is currently available, the most up-to-date known version of
  5. * the data is returned. If the node is not currently available, null is
  6. * returned.
  7. * @param refresh whether to refresh the data by calling ZK directly.
  8. * @return data of the node, null if unavailable
  9. */
  10. public synchronized byte [] getData(boolean refresh) {
  11. if (refresh) {
  12. try {
  13. this.data = ZKUtil.getDataAndWatch(watcher, node);
  14. } catch(KeeperException e) {
  15. abortable.abort("Unexpected exception handling getData", e);
  16. }
  17. }
  18. return this.data;
  19. }

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

  1. @Override
  2. public synchronized void nodeCreated(String path) {
  3. if (!path.equals(node)) return;
  4. try {
  5. byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  6. if (data != null) {
  7. this.data = data;
  8. notifyAll();
  9. } else {
  10. nodeDeleted(path);
  11. }
  12. } catch(KeeperException e) {
  13. abortable.abort("Unexpected exception handling nodeCreated event", e);
  14. }
  15. }

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

  1. @Override
  2. public synchronized void nodeCreated(String path) {
  3. if (!path.equals(node)) return;
  4. try {
  5. byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  6. if (data != null) {
  7. this.data = data;
  8. notifyAll();
  9. } else {
  10. nodeDeleted(path);
  11. }
  12. } catch(KeeperException e) {
  13. abortable.abort("Unexpected exception handling nodeCreated event", e);
  14. }
  15. }

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

  1. @Override
  2. public synchronized void nodeCreated(String path) {
  3. if (!path.equals(node)) {
  4. return;
  5. }
  6. try {
  7. byte [] data = ZKUtil.getDataAndWatch(watcher, node);
  8. if (data != null) {
  9. this.data = data;
  10. notifyAll();
  11. } else {
  12. nodeDeleted(path);
  13. }
  14. } catch(KeeperException e) {
  15. abortable.abort("Unexpected exception handling nodeCreated event", e);
  16. }
  17. }

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

  1. public void start() throws KeeperException {
  2. watcher.registerListener(this);
  3. ZKUtil.createWithParents(watcher, labelZnode);
  4. ZKUtil.createWithParents(watcher, userAuthsZnode);
  5. byte[] data = ZKUtil.getDataAndWatch(watcher, labelZnode);
  6. if (data != null && data.length > 0) {
  7. refreshVisibilityLabelsCache(data);
  8. }
  9. data = ZKUtil.getDataAndWatch(watcher, userAuthsZnode);
  10. if (data != null && data.length > 0) {
  11. refreshUserAuthsCache(data);
  12. }
  13. }

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

  1. public void stop() {
  2. try {
  3. // If our address is in ZK, delete it on our way out
  4. byte [] bytes =
  5. ZKUtil.getDataAndWatch(watcher, watcher.masterAddressZNode);
  6. // TODO: redo this to make it atomic (only added for tests)
  7. ServerName master = bytes == null ? null : ServerName.parseVersionedServerName(bytes);
  8. if (master != null && master.equals(this.sn)) {
  9. ZKUtil.deleteNode(watcher, watcher.masterAddressZNode);
  10. }
  11. } catch (KeeperException e) {
  12. LOG.error(this.watcher.prefix("Error deleting our own master address node"), e);
  13. }
  14. }
  15. }

相关文章