com.github.zkclient.ZkClient.close()方法的使用及代码示例

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

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

ZkClient.close介绍

暂无

代码示例

代码示例来源:origin: adyliu/jafka

public void close() {
  this.zkClient.close();
}

代码示例来源:origin: adyliu/jafka

/**
 *
 */
public void close() {
  if (zkClient != null) {
    logger.info("closing zookeeper client...");
    zkClient.close();
  }
}

代码示例来源:origin: adyliu/jafka

public void close() throws IOException {
  synchronized (lock) {
    if (zkClient == null) {
      logger.warn("cannot shutdown already shutdown topic event watcher.");
      return;
    }
    stopWatchingTopicEvents();
    zkClient.close();
    zkClient = null;
  }
}

代码示例来源:origin: adyliu/jafka

static void tryCleanupZookeeper(String zkConnect, String groupId) {
    try {
      String dir = "/consumers/" + groupId;
      ZkClient zk = new ZkClient(zkConnect, 30 * 1000, 30 * 1000);
      zk.deleteRecursive(dir);
      zk.close();
    } catch (ZkInterruptedException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: adyliu/jafka

public void close() throws IOException {
  if (isShuttingDown.compareAndSet(false, true)) {
    logger.info("ZkConsumerConnector shutting down");
    try {
      scheduler.shutdown();
      if (fetcher != null) {
        fetcher.stopConnectionsToAllBrokers();
      }
      sendShutdownToAllQueues();
      if (config.isAutoCommit()) {
        commitOffsets();
      }
      //waiting rebalance listener to closed and then shutdown the zkclient
      for (ZKRebalancerListener<?> listener : this.rebalancerListeners) {
        Closer.closeQuietly(listener);
      }
      if (this.zkClient != null) {
        this.zkClient.close();
        zkClient = null;
      }
    } catch (Exception e) {
      logger.error("error during consumer connector shutdown", e);
    }
    logger.info("ZkConsumerConnector shut down completed");
  }
}

代码示例来源:origin: adyliu/zkclient

_zkClient.close();
} catch (ZkException e) {
  LOG.warn("Error on closing zkclient: " + e.getClass().getName());

代码示例来源:origin: com.github.adyliu/zkclient

_zkClient.close();
} catch (ZkException e) {
  LOG.warn("Error on closing zkclient: " + e.getClass().getName());

代码示例来源:origin: com.github.adyliu/zkclient

public synchronized void connect(final long maxMsToWaitUntilConnected, Watcher watcher) {
  if (_eventThread != null) {
    return;
  }
  boolean started = false;
  try {
    getEventLock().lockInterruptibly();
    setShutdownTrigger(false);
    _eventThread = new ZkEventThread(_connection.getServers());
    _eventThread.start();
    _connection.connect(watcher);
    LOG.debug("Awaiting connection to Zookeeper server: " + maxMsToWaitUntilConnected);
    if (!waitUntilConnected(maxMsToWaitUntilConnected, TimeUnit.MILLISECONDS)) {
      throw new ZkTimeoutException(String.format(
          "Unable to connect to zookeeper server[%s] within timeout %dms", _connection.getServers(), maxMsToWaitUntilConnected));
    }
    started = true;
  } catch (InterruptedException e) {
    States state = _connection.getZookeeperState();
    throw new IllegalStateException("Not connected with zookeeper server yet. Current state is " + state);
  } finally {
    getEventLock().unlock();
    // we should close the zookeeper instance, otherwise it would keep
    // on trying to connect
    if (!started) {
      close();
    }
  }
}

代码示例来源:origin: adyliu/zkclient

public synchronized void connect(final long maxMsToWaitUntilConnected, Watcher watcher) {
  if (_eventThread != null) {
    return;
  }
  boolean started = false;
  try {
    getEventLock().lockInterruptibly();
    setShutdownTrigger(false);
    _eventThread = new ZkEventThread(_connection.getServers());
    _eventThread.start();
    _connection.connect(watcher);
    LOG.debug("Awaiting connection to Zookeeper server: " + maxMsToWaitUntilConnected);
    if (!waitUntilConnected(maxMsToWaitUntilConnected, TimeUnit.MILLISECONDS)) {
      throw new ZkTimeoutException(String.format(
          "Unable to connect to zookeeper server[%s] within timeout %dms", _connection.getServers(), maxMsToWaitUntilConnected));
    }
    started = true;
  } catch (InterruptedException e) {
    States state = _connection.getZookeeperState();
    throw new IllegalStateException("Not connected with zookeeper server yet. Current state is " + state);
  } finally {
    getEventLock().unlock();
    // we should close the zookeeper instance, otherwise it would keep
    // on trying to connect
    if (!started) {
      close();
    }
  }
}

相关文章