org.apache.helix.manager.zk.ZkClient.waitUntilConnected()方法的使用及代码示例

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

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

ZkClient.waitUntilConnected介绍

暂无

代码示例

代码示例来源:origin: apache/incubator-pinot

public void start(ControllerMetrics controllerMetrics) {
 _controllerMetrics = controllerMetrics;
 LOGGER.info("Starting realtime segments manager, adding a listener on the property store table configs path.");
 String zkUrl = _pinotHelixResourceManager.getHelixZkURL();
 _zkClient = new ZkClient(zkUrl, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT);
 _zkClient.setZkSerializer(new ZNRecordSerializer());
 _zkClient.waitUntilConnected(CommonConstants.Helix.ZkClient.DEFAULT_CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS);
 // Subscribe to any data/child changes to property
 _zkClient.subscribeChildChanges(_tableConfigPath, this);
 _zkClient.subscribeDataChanges(_tableConfigPath, this);
 // Subscribe to leadership changes
 ControllerLeadershipManager.getInstance().subscribe(PinotLLCRealtimeSegmentManager.class.getName(), this);
 // Setup change listeners for already existing tables, if any.
 processPropertyStoreChange(_tableConfigPath);
}

代码示例来源:origin: apache/incubator-pinot

PinotHelixSegmentOnlineOfflineStateModelGenerator.generatePinotStateModelDefinition();
ZkClient zkClient = new ZkClient(zkPath);
zkClient.waitUntilConnected(CommonConstants.Helix.ZkClient.DEFAULT_CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS);
zkClient.setZkSerializer(new ZNRecordSerializer());
HelixDataAccessor accessor =

代码示例来源:origin: apache/incubator-pinot

zkClient.setZkSerializer(new ZNRecordStreamingSerializer());
LOGGER.info("Connecting to Zookeeper at: {}", _zkAddress);
zkClient.waitUntilConnected(CommonConstants.Helix.ZkClient.DEFAULT_CONNECT_TIMEOUT_SEC, TimeUnit.SECONDS);
ZkBaseDataAccessor<ZNRecord> baseDataAccessor = new ZkBaseDataAccessor<>(zkClient);
ZKHelixDataAccessor zkHelixDataAccessor = new ZKHelixDataAccessor(_clusterName, baseDataAccessor);

代码示例来源:origin: org.apache.helix/helix-core

@Override
public boolean isConnected() {
 if (_zkclient == null || _zkclient.isClosed()) {
  return false;
 }
 // Don't check ZkConnection state, which is different from ZkClient's watcher state.
 // ZkConnection state is the internal state of the connection, which can be different from the
 // ZkClient state due to internal thread/retry logic.
 try {
  return _zkclient.waitUntilConnected(0, TimeUnit.MILLISECONDS);
 } catch (ZkInterruptedException ex) {
  return false;
 }
}

代码示例来源:origin: org.apache.helix/helix-core

public ZKHelixAdmin(String zkAddress) {
 int timeOutInSec = Integer.parseInt(System.getProperty(CONNECTION_TIMEOUT, "30"));
 _zkClient = new ZkClient(zkAddress, timeOutInSec * 1000);
 _zkClient.setZkSerializer(new ZNRecordSerializer());
 _zkClient.waitUntilConnected(timeOutInSec, TimeUnit.SECONDS);
 _configAccessor = new ConfigAccessor(_zkClient);
}

代码示例来源:origin: org.apache.helix/helix-core

/**
 * Check if HelixManager is connected, if it is not connected,
 * wait for the specified timeout and check again before return.
 *
 * @param timeout
 */
void checkConnected(long timeout) {
 if (_zkclient == null || _zkclient.isClosed()) {
  throw new HelixException(
    "HelixManager (ZkClient) is not connected. Call HelixManager#connect()");
 }
 boolean isConnected = isConnected();
 if (!isConnected && timeout > 0) {
  LOG.warn(
    "zkClient to " + _zkAddress + " is not connected, wait for " + _waitForConnectedTimeout
      + "ms.");
  isConnected = _zkclient.waitUntilConnected(_waitForConnectedTimeout, TimeUnit.MILLISECONDS);
 }
 if (!isConnected) {
  LOG.error("zkClient is not connected after waiting " + timeout + "ms."
    + ", clusterName: " + _clusterName + ", zkAddress: " + _zkAddress);
  throw new HelixException(
    "HelixManager is not connected within retry timeout for cluster " + _clusterName);
 }
}

代码示例来源:origin: org.apache.helix/helix-core

/**
 * wait until we get a non-zero session-id. note that we might lose zkconnection
 * right after we read session-id. but it's ok to get stale session-id and we will have
 * another handle-new-session callback to correct this.
 */
void waitUntilConnected() {
 boolean isConnected;
 do {
  isConnected =
    _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
  if (!isConnected) {
   LOG.error("fail to connect zkserver: " + _zkAddress + " in "
     + ZkClient.DEFAULT_CONNECTION_TIMEOUT + "ms. expiredSessionId: " + _sessionId
     + ", clusterName: " + _clusterName);
   continue;
  }
  ZkConnection zkConnection = ((ZkConnection) _zkclient.getConnection());
  _sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
  /**
   * at the time we read session-id, zkconnection might be lost again
   * wait until we get a non-zero session-id
   */
 } while (!isConnected || "0".equals(_sessionId));
 LOG.info("Handling new session, session id: " + _sessionId + ", instance: " + _instanceName
   + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName + ", zkconnection: "
   + ((ZkConnection) _zkclient.getConnection()).getZookeeper());
}

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

@Override
public void handleNewSession() throws Exception {
 // make sure zkclient is connected again
 zkClient.waitUntilConnected(HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
 ZkConnection connection = ((ZkConnection) zkClient.getConnection());
 ZooKeeper curZookeeper = connection.getZookeeper();
 LOG.info("handleNewSession. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
 waitNewSession.countDown();
}

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

@Override
public void handleNewSession() throws Exception {
 // make sure zkclient is connected again
 zkClient.waitUntilConnected(HelixZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.SECONDS);
 ZkConnection connection = ((ZkConnection) zkClient.getConnection());
 ZooKeeper curZookeeper = connection.getZookeeper();
 LOG.info("handleNewSession. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}

代码示例来源:origin: org.apache.helix/helix-core

public ZkCacheBaseDataAccessor(String zkAddress, ZkSerializer serializer, String chrootPath,
  List<String> wtCachePaths, List<String> zkCachePaths, String monitorType, String monitorkey) {
 ZkClient.Builder zkClientBuilder = new ZkClient.Builder();
 zkClientBuilder.setZkServer(zkAddress).setSessionTimeout(ZkClient.DEFAULT_SESSION_TIMEOUT)
   .setConnectionTimeout(ZkClient.DEFAULT_CONNECTION_TIMEOUT).setZkSerializer(serializer)
   .setMonitorType(monitorType).setMonitorKey(monitorkey);
 _zkclient = zkClientBuilder.build();
 _zkclient.waitUntilConnected(ZkClient.DEFAULT_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
 _baseAccessor = new ZkBaseDataAccessor<>(_zkclient);
 if (chrootPath == null || chrootPath.equals("/")) {
  _chrootPath = null;
 } else {
  PathUtils.validatePath(chrootPath);
  _chrootPath = chrootPath;
 }
 _wtCachePaths = wtCachePaths;
 _zkCachePaths = zkCachePaths;
 // TODO: need to make sure no overlap between wtCachePaths and zkCachePaths
 // TreeMap key is ordered by key string length, so more general (i.e. short) prefix
 // comes first
 _cacheMap = new TreeMap<>(new Comparator<String>() {
  @Override
  public int compare(String o1, String o2) {
   int len1 = o1.split("/").length;
   int len2 = o2.split("/").length;
   return len1 - len2;
  }
 });
 start();
}

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

Assert.assertFalse(zkClient.waitUntilConnected(0, TimeUnit.MILLISECONDS));
Assert.assertTrue(zkClient.waitUntilConnected(5000, TimeUnit.MILLISECONDS));
Assert.assertTrue(TestHelper.verify(new TestHelper.Verifier() {
 @Override

代码示例来源:origin: org.apache.helix/helix-core

while (retryCount < 3) {
 try {
  _zkclient.waitUntilConnected(_connectionInitTimeout, TimeUnit.MILLISECONDS);
  handleStateChanged(KeeperState.SyncConnected);
  handleNewSession();

相关文章