com.alibaba.wasp.zookeeper.ZKUtil.getDataAndWatch()方法的使用及代码示例

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

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

  1. /**
  2. * Gets the current data in the unassigned node for the specified entityGroup
  3. * name or fully-qualified path.
  4. *
  5. * <p>
  6. * Returns null if the entityGroup does not currently have a node.
  7. *
  8. * <p>
  9. * Sets a watch on the node if the node exists.
  10. *
  11. * @param zkw zk reference
  12. * @param pathOrEntityGroupName fully-specified path or entityGroup name
  13. * @return znode content
  14. * @throws org.apache.zookeeper.KeeperException if unexpected zookeeper exception
  15. */
  16. public static byte[] getData(ZooKeeperWatcher zkw, String pathOrEntityGroupName)
  17. throws KeeperException {
  18. String node = getPath(zkw, pathOrEntityGroupName);
  19. return ZKUtil.getDataAndWatch(zkw, node);
  20. }

代码示例来源:origin: alibaba/wasp

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

代码示例来源:origin: alibaba/wasp

  1. /**
  2. * Gets the current data in the unassigned node for the specified entityGroup
  3. * name or fully-qualified path.
  4. *
  5. * <p>
  6. * Returns null if the entityGroup does not currently have a node.
  7. *
  8. * <p>
  9. * Sets a watch on the node if the node exists.
  10. *
  11. * @param zkw zk reference
  12. * @param pathOrEntityGroupName fully-specified path or entityGroup name
  13. * @param stat object to populate the version.
  14. * @return znode content
  15. * @throws org.apache.zookeeper.KeeperException if unexpected zookeeper exception
  16. */
  17. public static byte[] getDataAndWatch(ZooKeeperWatcher zkw,
  18. String pathOrEntityGroupName, Stat stat) throws KeeperException {
  19. String node = getPath(zkw, pathOrEntityGroupName);
  20. return ZKUtil.getDataAndWatch(zkw, node, stat);
  21. }

代码示例来源:origin: alibaba/wasp

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

代码示例来源:origin: alibaba/wasp

  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: alibaba/wasp

  1. try {
  2. if (ZKUtil.watchAndCheckExists(watcher, node)) {
  3. byte[] data = ZKUtil.getDataAndWatch(watcher, node);
  4. if (data != null) {
  5. this.data = data;

代码示例来源:origin: alibaba/wasp

  1. byte[] bytes = ZKUtil.getDataAndWatch(this.watcher,
  2. this.watcher.getMasterAddressZNode());
  3. if (bytes == null) {

代码示例来源:origin: alibaba/wasp

  1. existingBytes = ZKUtil.getDataAndWatch(zkw, node);
  2. } catch (KeeperException.NoNodeException nne) {
  3. return false;

代码示例来源:origin: alibaba/wasp

  1. String nodeName = ZKAssign.getNodeName(zkw, entityGroup
  2. .getEntityGroupInfo().getEncodedName());
  3. ZKUtil.getDataAndWatch(zkw, nodeName, stat);

相关文章