當前位置: 首頁>>代碼示例>>Java>>正文


Java HConstants.SOCKET_RETRY_WAIT_MS屬性代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.HConstants.SOCKET_RETRY_WAIT_MS屬性的典型用法代碼示例。如果您正苦於以下問題:Java HConstants.SOCKET_RETRY_WAIT_MS屬性的具體用法?Java HConstants.SOCKET_RETRY_WAIT_MS怎麽用?Java HConstants.SOCKET_RETRY_WAIT_MS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.hadoop.hbase.HConstants的用法示例。


在下文中一共展示了HConstants.SOCKET_RETRY_WAIT_MS屬性的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: blockUntilAvailable

/**
 * Wait until the meta region is available and is not in transition.
 * @param zkw
 * @param replicaId
 * @param timeout
 * @return ServerName or null if we timed out.
 * @throws InterruptedException
 */
public ServerName blockUntilAvailable(final ZooKeeperWatcher zkw, int replicaId,
    final long timeout)
throws InterruptedException {
  if (timeout < 0) throw new IllegalArgumentException();
  if (zkw == null) throw new IllegalArgumentException();
  Stopwatch sw = new Stopwatch().start();
  ServerName sn = null;
  try {
    while (true) {
      sn = getMetaRegionLocation(zkw, replicaId);
      if (sn != null || sw.elapsedMillis()
          > timeout - HConstants.SOCKET_RETRY_WAIT_MS) {
        break;
      }
      Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
    }
  } finally {
    sw.stop();
  }
  return sn;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:29,代碼來源:MetaTableLocator.java

示例2: waitForBaseZNode

/**
 * Waits for HBase installation's base (parent) znode to become available.
 * @throws IOException on ZK errors
 */
public static void waitForBaseZNode(Configuration conf) throws IOException {
  LOG.info("Waiting until the base znode is available");
  String parentZNode = conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT,
      HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT);
  ZooKeeper zk = new ZooKeeper(ZKConfig.getZKQuorumServersString(conf),
      conf.getInt(HConstants.ZK_SESSION_TIMEOUT,
      HConstants.DEFAULT_ZK_SESSION_TIMEOUT), EmptyWatcher.instance);

  final int maxTimeMs = 10000;
  final int maxNumAttempts = maxTimeMs / HConstants.SOCKET_RETRY_WAIT_MS;

  KeeperException keeperEx = null;
  try {
    try {
      for (int attempt = 0; attempt < maxNumAttempts; ++attempt) {
        try {
          if (zk.exists(parentZNode, false) != null) {
            LOG.info("Parent znode exists: " + parentZNode);
            keeperEx = null;
            break;
          }
        } catch (KeeperException e) {
          keeperEx = e;
        }
        Threads.sleepWithoutInterrupt(HConstants.SOCKET_RETRY_WAIT_MS);
      }
    } finally {
      zk.close();
    }
  } catch (InterruptedException ex) {
    Thread.currentThread().interrupt();
  }

  if (keeperEx != null) {
    throw new IOException(keeperEx);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:41,代碼來源:ZKUtil.java

示例3: blockUntilAvailable

public static byte[] blockUntilAvailable(
  final ZooKeeperWatcher zkw, final String znode, final long timeout)
  throws InterruptedException {
  if (timeout < 0) throw new IllegalArgumentException();
  if (zkw == null) throw new IllegalArgumentException();
  if (znode == null) throw new IllegalArgumentException();

  byte[] data = null;
  boolean finished = false;
  final long endTime = System.currentTimeMillis() + timeout;
  while (!finished) {
    try {
      data = ZKUtil.getData(zkw, znode);
    } catch(KeeperException e) {
      if (e instanceof KeeperException.SessionExpiredException
          || e instanceof KeeperException.AuthFailedException) {
        // non-recoverable errors so stop here
        throw new InterruptedException("interrupted due to " + e);
      }
      LOG.warn("Unexpected exception handling blockUntilAvailable", e);
    }

    if (data == null && (System.currentTimeMillis() +
      HConstants.SOCKET_RETRY_WAIT_MS < endTime)) {
      Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
    } else {
      finished = true;
    }
  }

  return data;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:ZKUtil.java


注:本文中的org.apache.hadoop.hbase.HConstants.SOCKET_RETRY_WAIT_MS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。