本文整理匯總了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;
}
示例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);
}
}
示例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;
}