gpt4 book ai didi

org.apache.zookeeper.ZooKeeper.close()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 17:44:40 28 4
gpt4 key购买 nike

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

ZooKeeper.close介绍

[英]Close this client object. Once the client is closed, its session becomes invalid. All the ephemeral nodes in the ZooKeeper server associated with the session will be removed. The watches left on those nodes (and on their parents) will be triggered.

Added in 3.5.3: try-with-resources may be used instead of calling close directly.

This method does not wait for all internal threads to exit. Use the #close(int) method to wait for all resources to be released
[中]关闭此客户端对象。一旦客户机关闭,其会话将无效。ZooKeeper服务器中与会话关联的所有短暂节点都将被删除。将触发留在这些节点(及其父节点)上的手表。
在3.5.3中添加:try-with-resources可以用来代替直接调用close。
此方法不会等待所有内部线程退出。使用#close(int)方法等待释放所有资源

代码示例

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

@Override
public boolean exec() throws CliException {
  try {
    zk.close();
  } catch (Exception ex) {
    throw new CliWrapperException(ex);
  }
  
  return false;
}

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

public void restartClient(int clientIndex, Watcher watcher) throws IOException, InterruptedException {
  if (zk[clientIndex] != null) {
    zk[clientIndex].close();
  }
  zk[clientIndex] = new ZooKeeper("127.0.0.1:" + clientPorts[clientIndex], ClientBase.CONNECTION_TIMEOUT, watcher);
}

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

@Override
public void tearDown() throws Exception {
  client.close();
  lsnr.close();
  super.tearDown();
}

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

private void utestPrep(int port)
  throws IOException, InterruptedException, KeeperException
{
  ZooKeeper zk =
    new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this);
  for (int i = 0; i < 10000; i++) {
    zk.create("/" + i, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  }
  zk.close();
}

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

private void utestChildren(int port)
  throws IOException, InterruptedException, KeeperException
{
  ZooKeeper zk =
    new ZooKeeper("127.0.0.1:" + port, CONNECTION_TIMEOUT, this);
  for (int i = 0; i < 10000; i++) {
    zk.getChildren("/" + i, true);
  }
  zk.close();
}

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

@Override
public void tearDown() throws Exception {
  if (zk1 != null)
    zk1.close();
  if (zk2 != null)
    zk2.close();
  super.tearDown();
}

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

@Override
public void tearDown() throws Exception {
  super.tearDown();
  zk.close();
}

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

@Override
public void tearDown() throws Exception {
  super.tearDown();
  zk.close();
}

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

public static void closeAllHandles(ZooKeeper[] zkArr, ZooKeeperAdmin[] zkAdminArr) throws InterruptedException {
  if (zkArr != null) {
    for (ZooKeeper zk : zkArr)
      if (zk != null)
        zk.close();
  }
  if (zkAdminArr != null) {
    for (ZooKeeperAdmin zkAdmin : zkAdminArr)
      if (zkAdmin != null)
        zkAdmin.close();
  }
}

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

@Override
public void tearDown() throws Exception {
  super.tearDown();
  zk.close();
}

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

@Override
public void tearDown() throws Exception {
  super.tearDown();
  zk.close();
}

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

@Override
public void tearDown() throws Exception {
 super.tearDown();
 zk.close();
}

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

@Override
public void tearDown() throws Exception {
  if (zk != null) {
    zk.close();
  }
  super.tearDown();
}

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

protected void connectToZK(String newHost) throws InterruptedException, IOException {
  if (zk != null && zk.getState().isAlive()) {
    zk.close();
  }
  host = newHost;
  boolean readOnly = cl.getOption("readonly") != null;
  if (cl.getOption("secure") != null) {
    System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
    System.out.println("Secure connection is enabled");
  }
  zk = new ZooKeeperAdmin(host, Integer.parseInt(cl.getOption("timeout")), new MyWatcher(), readOnly);
}

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

@Test
public void testAuth() throws Exception {
  ZooKeeper zk = createClient();
  try {
    zk.create("/path1", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT);
    Thread.sleep(1000);
  } finally {
    zk.close();
  }
}

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

@After
@Override
public void tearDown() throws Exception {
  zk.close();
  super.tearDown();
  LOG.info("Test clients shutting down");
}

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

@After
public void tearDown() throws Exception {
  LOG.info("tearDown starting");
  for (int i = 0; i < zkClients.length; i++) {
    zkClients[i].close();
  }
  qu.shutdownAll();
}

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

private void verifySessionTimeOut(int sessionTimeout,
    int expectedSessionTimeout, String HOSTPORT) throws IOException,
    KeeperException, InterruptedException {
  clientConnected = new CountDownLatch(1);
  ZooKeeper zk = new ZooKeeper(HOSTPORT, sessionTimeout, this);
  Assert.assertTrue("Failed to establish zkclient connection!",
      clientConnected.await(sessionTimeout, TimeUnit.MILLISECONDS));
  Assert.assertEquals("Not able to configure the sessionTimeout values",
      expectedSessionTimeout, zk.getSessionTimeout());
  zk.close();
}

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

private void verifyQuorumConfig(int sid, List<String> joiningServers, List<String> leavingServers) throws Exception {
  ZooKeeper zk = ClientBase.createZKClient("127.0.0.1:" + clientPorts.get(sid));
  ReconfigTest.testNormalOperation(zk, zk);
  ReconfigTest.testServerHasConfig(zk, joiningServers, leavingServers);
  zk.close();
}

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

@Test
public void testWatcherAutoResetWithGlobal() throws Exception {
  ZooKeeper zk = null;
  MyWatcher watcher = new MyWatcher();
  zk = createClient(watcher, hostPort, TIMEOUT);
  testWatcherAutoReset(zk, watcher, watcher);
  zk.close();
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com