org.apache.ignite.spi.discovery.zk.internal.ZookeeperClient.getChildren()方法的使用及代码示例

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

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

ZookeeperClient.getChildren介绍

暂无

代码示例

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

/**
 * Get children paths.
 *
 * @param path Path.
 * @return Children paths.
 * @throws ZookeeperClientFailedException If connection to zk was lost.
 * @throws InterruptedException If interrupted.
 */
List<String> getChildrenPaths(String path) throws ZookeeperClientFailedException, InterruptedException {
  List<String> children = getChildren(path);
  ArrayList<String> paths = new ArrayList(children.size());
  for (String child : children)
    paths.add(path + "/" + child);
  return paths;
}

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

/**
 * @param startInternalOrder Starting internal order for cluster (znodes having lower order belong
 *      to clients from previous cluster and should be removed).
 * @throws Exception If failed.
 */
private void cleanupPreviousClusterData(long startInternalOrder) throws Exception {
  long start = System.currentTimeMillis();
  ZookeeperClient client = rtState.zkClient;
  List<String> batch = new LinkedList<>();
  List<String> evtChildren = client.getChildrenPaths(zkPaths.evtsPath);
  for (String evtPath : evtChildren)
    batch.addAll(client.getChildrenPaths(evtPath));
  batch.addAll(evtChildren);
  batch.addAll(client.getChildrenPaths(zkPaths.customEvtsDir));
  batch.addAll(client.getChildrenPaths(zkPaths.customEvtsPartsDir));
  batch.addAll(client.getChildrenPaths(zkPaths.customEvtsAcksDir));
  client.deleteAll(batch, -1);
  if (startInternalOrder > 0) {
    for (String alive : client.getChildren(zkPaths.aliveNodesDir)) {
      if (ZkIgnitePaths.aliveInternalId(alive) < startInternalOrder)
        client.deleteIfExists(zkPaths.aliveNodesDir + "/" + alive, -1);
    }
  }
  long time = System.currentTimeMillis() - start;
  if (time > 0) {
    if (log.isInfoEnabled())
      log.info("Previous cluster data cleanup time: " + time);
  }
}

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

aliveNodes = rtState.zkClient.getChildren(zkPaths.aliveNodesDir);

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

/**
 * @param internalIds Nodes internal IDs.
 * @throws Exception If failed.
 */
private void deleteAliveNodes(@Nullable GridLongList internalIds) throws Exception {
  if (internalIds == null)
    return;
  List<String> alives = rtState.zkClient.getChildren(zkPaths.aliveNodesDir);
  for (int i = 0; i < alives.size(); i++) {
    String alive = alives.get(i);
    if (internalIds.contains(ZkIgnitePaths.aliveInternalId(alive)))
      rtState.zkClient.deleteIfExistsAsync(zkPaths.aliveNodesDir + "/" + alive);
  }
}

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

/**
 * @param internalId Node internal ID.
 * @throws Exception If failed.
 */
private void deleteAliveNode(long internalId) throws Exception {
  for (String child : rtState.zkClient.getChildren(zkPaths.aliveNodesDir)) {
    if (ZkIgnitePaths.aliveInternalId(child) == internalId) {
      // Need use sync delete to do not process again join of this node again.
      rtState.zkClient.deleteIfExists(zkPaths.aliveNodesDir + "/" + child, -1);
      return;
    }
  }
}

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

List<String> createdDirs = client.getChildren(zkPaths.clusterDir);

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

/**
 * @param nodeId Node ID.
 * @return {@code True} if node joined or joining topology.
 */
public boolean knownNode(UUID nodeId) {
  while (!busyLock.enterBusy())
    checkState();
  try {
    List<String> children = rtState.zkClient.getChildren(zkPaths.aliveNodesDir);
    for (int i = 0; i < children.size(); i++) {
      UUID id = ZkIgnitePaths.aliveNodeId(children.get(i));
      if (nodeId.equals(id))
        return true;
    }
    return false;
  }
  catch (ZookeeperClientFailedException e) {
    if (clientReconnectEnabled)
      throw new IgniteClientDisconnectedException(null, "Client is disconnected.");
    throw new IgniteException(e);
  }
  catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new IgniteInterruptedException(e);
  }
  finally {
    busyLock.leaveBusy();
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateAll() throws Exception {
  startZK(1);
  ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
  List<String> paths = new ArrayList<>();
  paths.add("/apacheIgnite/1");
  paths.add("/apacheIgnite/2");
  paths.add("/apacheIgnite/3");
  client.createAll(paths, CreateMode.PERSISTENT);
  assertEquals(3, client.getChildren("/apacheIgnite").size());
}

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

@Override protected void run0() throws Exception {
  if (checkNodeAndState()) {
    try {
      for (String path : rtState.zkClient.getChildren(zkPaths.aliveNodesDir)) {
        if (node.internalId() == ZkIgnitePaths.aliveInternalId(path)) {
          onDone(true);
          return;
        }
      }
      onDone(false);
    }
    catch (Exception e) {
      onDone(e);
      throw e;
    }
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testCreateAllNodeExists() throws Exception {
  startZK(1);
  ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/1", null, CreateMode.PERSISTENT);
  List<String> paths = new ArrayList<>();
  paths.add("/apacheIgnite/1");
  paths.add("/apacheIgnite/2");
  paths.add("/apacheIgnite/3");
  client.createAll(paths, CreateMode.PERSISTENT);
  assertEquals(3, client.getChildren("/apacheIgnite").size());
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testDeleteAll() throws Exception {
  startZK(1);
  ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/1", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/2", null, CreateMode.PERSISTENT);
  client.deleteAll(Arrays.asList("/apacheIgnite/1", "/apacheIgnite/2"), -1);
  assertTrue(client.getChildren("/apacheIgnite").isEmpty());
  client.createIfNeeded("/apacheIgnite/1", null, CreateMode.PERSISTENT);
  client.deleteAll(Collections.singletonList("/apacheIgnite/1"), -1);
  assertTrue(client.getChildren("/apacheIgnite").isEmpty());
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testDeleteAllNoNode() throws Exception {
  startZK(1);
  ZookeeperClient client = createClient(SES_TIMEOUT);
  client.createIfNeeded("/apacheIgnite", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/1", null, CreateMode.PERSISTENT);
  client.createIfNeeded("/apacheIgnite/2", null, CreateMode.PERSISTENT);
  client.deleteAll(Arrays.asList("/apacheIgnite/1", "/apacheIgnite/2", "/apacheIgnite/3"), -1);
  assertTrue(client.getChildren("/apacheIgnite").isEmpty());
}

相关文章