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

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

本文整理了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

/**
 * Gets the current data in the unassigned node for the specified entityGroup
 * name or fully-qualified path.
 *
 * <p>
 * Returns null if the entityGroup does not currently have a node.
 *
 * <p>
 * Sets a watch on the node if the node exists.
 *
 * @param zkw zk reference
 * @param pathOrEntityGroupName fully-specified path or entityGroup name
 * @return znode content
 * @throws org.apache.zookeeper.KeeperException if unexpected zookeeper exception
 */
public static byte[] getData(ZooKeeperWatcher zkw, String pathOrEntityGroupName)
  throws KeeperException {
 String node = getPath(zkw, pathOrEntityGroupName);
 return ZKUtil.getDataAndWatch(zkw, node);
}

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

/**
 * Gets the data of the node.
 * 
 * <p>
 * If the node is currently available, the most up-to-date known version of
 * the data is returned. If the node is not currently available, null is
 * returned.
 * @param refresh whether to refresh the data by calling ZK directly.
 * @return data of the node, null if unavailable
 */
public synchronized byte[] getData(boolean refresh) {
 if (refresh) {
  try {
   this.data = ZKUtil.getDataAndWatch(watcher, node);
  } catch (KeeperException e) {
   abortable.abort("Unexpected exception handling getData", e);
  }
 }
 return this.data;
}

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

/**
 * Gets the current data in the unassigned node for the specified entityGroup
 * name or fully-qualified path.
 *
 * <p>
 * Returns null if the entityGroup does not currently have a node.
 *
 * <p>
 * Sets a watch on the node if the node exists.
 *
 * @param zkw zk reference
 * @param pathOrEntityGroupName fully-specified path or entityGroup name
 * @param stat object to populate the version.
 * @return znode content
 * @throws org.apache.zookeeper.KeeperException if unexpected zookeeper exception
 */
public static byte[] getDataAndWatch(ZooKeeperWatcher zkw,
  String pathOrEntityGroupName, Stat stat) throws KeeperException {
 String node = getPath(zkw, pathOrEntityGroupName);
 return ZKUtil.getDataAndWatch(zkw, node, stat);
}

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

@Override
public synchronized void nodeCreated(String path) {
 if (!path.equals(node))
  return;
 try {
  byte[] data = ZKUtil.getDataAndWatch(watcher, node);
  if (data != null) {
   this.data = data;
   notifyAll();
  } else {
   nodeDeleted(path);
  }
 } catch (KeeperException e) {
  abortable.abort("Unexpected exception handling nodeCreated event", e);
 }
}

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

try {
 this.data = ZKUtil.getDataAndWatch(watcher, node);
} catch (KeeperException e) {
  try {
   this.data = ZKUtil.getDataAndWatch(watcher, node);
  } catch (KeeperException e) {
   LOG.warn("Unexpected exception handling blockUntilAvailable", e);

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

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

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

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

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

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

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

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

相关文章