当前位置: 首页>>代码示例>>Java>>正文


Java ZkNoNodeException类代码示例

本文整理汇总了Java中org.I0Itec.zkclient.exception.ZkNoNodeException的典型用法代码示例。如果您正苦于以下问题:Java ZkNoNodeException类的具体用法?Java ZkNoNodeException怎么用?Java ZkNoNodeException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ZkNoNodeException类属于org.I0Itec.zkclient.exception包,在下文中一共展示了ZkNoNodeException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createPersistentSequential

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
/**
 * Create a persistent Sequential node.
 * 
 * @param path
 * @param data
 * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
 * in case the path already exists
 * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public String createPersistentSequential(String path, Object data, boolean createParents)
                                                                                         throws ZkInterruptedException,
                                                                                         IllegalArgumentException,
                                                                                         ZkException,
                                                                                         RuntimeException {
    try {
        return create(path, data, CreateMode.PERSISTENT_SEQUENTIAL);
    } catch (ZkNoNodeException e) {
        if (!createParents) {
            throw e;
        }
        String parentDir = path.substring(0, path.lastIndexOf('/'));
        createPersistent(parentDir, createParents);
        return createPersistentSequential(path, data, createParents);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:29,代码来源:ZkClientx.java

示例2: deleteRecursive

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public boolean deleteRecursive(String path) {
    List<String> children;
    try {
        children = getChildren(path, false);
    } catch (ZkNoNodeException e) {
        return true;
    }

    for (String subPath : children) {
        if (!deleteRecursive(path + "/" + subPath)) {
            return false;
        }
    }

    return delete(path);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:17,代码来源:ZkClientx.java

示例3: fireDataChangedEvents

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
    for (final IZkDataListener listener : listeners) {
        _eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {

            @Override
            public void run() throws Exception {
                // reinstall watch
                exists(path, true);
                try {
                    Object data = readData(path, null, true);
                    listener.handleDataChange(path, data);
                } catch (ZkNoNodeException e) {
                    listener.handleDataDeleted(path);
                }
            }
        });
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:19,代码来源:ZkClientx.java

示例4: delete

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public boolean delete(final String path) {
    try {
        retryUntilConnected(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                _connection.delete(path);
                return null;
            }
        });

        return true;
    } catch (ZkNoNodeException e) {
        return false;
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:17,代码来源:ZkClientx.java

示例5: watchForChilds

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
/**
 * Installs a child watch for the given path.
 * 
 * @param path
 * @return the current children of the path or null if the zk node with the given path doesn't exist.
 */
public List<String> watchForChilds(final String path) {
    if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
        throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
    }
    return retryUntilConnected(new Callable<List<String>>() {

        @Override
        public List<String> call() throws Exception {
            exists(path, true);
            try {
                return getChildren(path, true);
            } catch (ZkNoNodeException e) {
                // ignore, the "exists" watch will listen for the parent node to appear
            }
            return null;
        }
    });
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:25,代码来源:ZkClientx.java

示例6: queryConfiguration

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
@RequestMapping("/queryConfiguration")
@ResponseBody
public JsonMessage queryConfiguration(Configuration configuration) {
	JsonMessage jsonMessage = new JsonMessage();
	try {
		Configuration configurationResult = configurationService.queryConfiguration(configuration);
		jsonMessage.setResult(configurationResult);
	} catch (ZkNoNodeException zkEx) {
		logger.error("error: ", zkEx);
		jsonMessage.setMessage("获取节点配置异常:节点文件为:" + configuration.getGroupId() + "-" + configuration.getDataId()+"不存在!");
		jsonMessage.setCode(500);
	} catch (Exception e) {
		logger.error("error: " + e.getMessage());
		jsonMessage.setMessage("服务器内部异常:请联系管理员!");
		jsonMessage.setCode(500);
	}
	return jsonMessage;
}
 
开发者ID:hncdyj123,项目名称:config-manager,代码行数:19,代码来源:FlowController.java

示例7: deleteRecursive

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public boolean deleteRecursive(String path) {
  List<String> children;
  try {
    children = getChildren(path, false);
  } catch (ZkNoNodeException e) {
    return true;
  }

  for (String subPath : children) {
    if (!deleteRecursive(path + "/" + subPath)) {
      return false;
    }
  }

  return delete(path);
}
 
开发者ID:apache,项目名称:helix,代码行数:17,代码来源:ZkClient.java

示例8: fireDataChangedEvents

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
private void fireDataChangedEvents(final String path, Set<IZkDataListener> listeners) {
  for (final IZkDataListener listener : listeners) {
    _eventThread.send(new ZkEvent("Data of " + path + " changed sent to " + listener) {

      @Override public void run() throws Exception {
        // reinstall watch
        exists(path, true);
        try {
          Object data = readData(path, null, true);
          listener.handleDataChange(path, data);
        } catch (ZkNoNodeException e) {
          listener.handleDataDeleted(path);
        }
      }
    });
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:18,代码来源:ZkClient.java

示例9: watchForChilds

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
/**
 * Installs a child watch for the given path.
 *
 * @param path
 * @return the current children of the path or null if the zk node with the given path doesn't exist.
 */
public List<String> watchForChilds(final String path) {
  if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
    throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
  }
  return retryUntilConnected(new Callable<List<String>>() {
    @Override public List<String> call() throws Exception {
      exists(path, true);
      try {
        return getChildren(path, true);
      } catch (ZkNoNodeException e) {
        // ignore, the "exists" watch will listen for the parent node to appear
      }
      return null;
    }
  });
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:ZkClient.java

示例10: getPropertyStat

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
@Override
public HelixProperty.Stat getPropertyStat(PropertyKey key) {
  PropertyType type = key.getType();
  String path = key.getPath();
  int options = constructOptions(type);
  try {
    Stat stat = _baseDataAccessor.getStat(path, options);
    if (stat != null) {
      return new HelixProperty.Stat(stat.getVersion(), stat.getCtime(), stat.getMtime());
    }
  } catch (ZkNoNodeException e) {

  }

  return null;
}
 
开发者ID:apache,项目名称:helix,代码行数:17,代码来源:ZKHelixDataAccessor.java

示例11: readZkRecursive

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public static void readZkRecursive(String path, Map<String, ZNode> map, ZkClient zkclient) {
  try {
    Stat stat = new Stat();
    ZNRecord record = zkclient.readData(path, stat);
    List<String> childNames = zkclient.getChildren(path);
    ZNode node = new ZNode(path, record, stat);
    node.addChildren(childNames);
    map.put(path, node);

    for (String childName : childNames) {
      String childPath = path + "/" + childName;
      readZkRecursive(childPath, map, zkclient);
    }
  } catch (ZkNoNodeException e) {
    // OK
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:18,代码来源:TestHelper.java

示例12: createEphemeralPathExpectConflict

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
/**
 * Create an ephemeral node with the given path and data.
 * Throw NodeExistException if node already exists.
 */
public static void createEphemeralPathExpectConflict(ZkClient client, String path, String data) {
    try {
        createEphemeralPath(client, path, data);
    } catch (ZkNodeExistsException e) {
        // this can happen when there is connection loss; make sure the data is what we intend to write
        String storedData = null;
        try {
            storedData = readData(client, path)._1;
        } catch (ZkNoNodeException e1) {
            // the node disappeared; treat as if node existed and let caller handles this
        }
        if (storedData == null || storedData != data) {
            logger.info("conflict in {} data: {} stored data: {}", path, data, storedData);
            throw e;
        } else {
            // otherwise, the creation succeeded, return normally
            logger.info("{} exists with value {} during connection loss; this is ok", path, data);
        }
    }
}
 
开发者ID:bingoohuang,项目名称:buka,代码行数:25,代码来源:ZkUtils.java

示例13: updatePartitionReassignmentData

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public static void updatePartitionReassignmentData(ZkClient zkClient, Multimap<TopicAndPartition, Integer> partitionsToBeReassigned) {
    String zkPath = ZkUtils.ReassignPartitionsPath;
    int size = partitionsToBeReassigned.size();
    switch (size) {
        case 0: // need to delete the /admin/reassign_partitions path
            deletePath(zkClient, zkPath);
            logger.info("No more partitions need to be reassigned. Deleting zk path {}", zkPath);
            break;
        default:
            String jsonData = getPartitionReassignmentZkData(partitionsToBeReassigned);
            try {
                updatePersistentPath(zkClient, zkPath, jsonData);
                logger.info("Updated partition reassignment path with {}", jsonData);
            } catch (ZkNoNodeException nne) {
                ZkUtils.createPersistentPath(zkClient, zkPath, jsonData);
                logger.debug("Created path {} with {} for partition reassignment", zkPath, jsonData);
            } catch (Throwable e) {
                throw new AdminOperationException(e.toString());
            }
    }
}
 
开发者ID:bingoohuang,项目名称:buka,代码行数:22,代码来源:ZkUtils.java

示例14: getLastestBatch

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public PositionRange getLastestBatch(ClientIdentity clientIdentity) {
    String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(), clientIdentity.getClientId());
    List<String> nodes = null;
    try {
        nodes = zkClientx.getChildren(path);
    } catch (ZkNoNodeException e) {
        // ignore
    }

    if (CollectionUtils.isEmpty(nodes)) {
        return null;
    }
    // 找到最大的Id
    ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
    for (String batchIdString : nodes) {
        batchIds.add(Long.valueOf(batchIdString));
    }
    Long maxBatchId = Collections.max(batchIds);
    PositionRange result = getBatch(clientIdentity, maxBatchId);
    if (result == null) { // 出现为null,说明zk节点有变化,重新获取
        return getLastestBatch(clientIdentity);
    } else {
        return result;
    }
}
 
开发者ID:alibaba,项目名称:canal,代码行数:26,代码来源:ZooKeeperMetaManager.java

示例15: getFirstBatch

import org.I0Itec.zkclient.exception.ZkNoNodeException; //导入依赖的package包/类
public PositionRange getFirstBatch(ClientIdentity clientIdentity) {
    String path = ZookeeperPathUtils.getBatchMarkPath(clientIdentity.getDestination(), clientIdentity.getClientId());
    List<String> nodes = null;
    try {
        nodes = zkClientx.getChildren(path);
    } catch (ZkNoNodeException e) {
        // ignore
    }

    if (CollectionUtils.isEmpty(nodes)) {
        return null;
    }
    // 找到最小的Id
    ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
    for (String batchIdString : nodes) {
        batchIds.add(Long.valueOf(batchIdString));
    }
    Long minBatchId = Collections.min(batchIds);
    PositionRange result = getBatch(clientIdentity, minBatchId);
    if (result == null) { // 出现为null,说明zk节点有变化,重新获取
        return getFirstBatch(clientIdentity);
    } else {
        return result;
    }
}
 
开发者ID:alibaba,项目名称:canal,代码行数:26,代码来源:ZooKeeperMetaManager.java


注:本文中的org.I0Itec.zkclient.exception.ZkNoNodeException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。