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


Java KeeperException.OperationTimeoutException方法代碼示例

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


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

示例1: init

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Override
public void init() {
	logger.debug("init zookeeper registry, connect to servers : {}", zkConfig.getServerLists());
	CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(zkConfig.getServerLists()).retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds())).namespace(zkConfig.getNamespace());
	if (0 != zkConfig.getSessionTimeoutMilliseconds()) {
		builder.sessionTimeoutMs(zkConfig.getSessionTimeoutMilliseconds());
	}
	if (0 != zkConfig.getConnectionTimeoutMilliseconds()) {
		builder.connectionTimeoutMs(zkConfig.getConnectionTimeoutMilliseconds());
	}
	if (zkConfig.getDigest() != null && !zkConfig.getDigest().isEmpty()) {
		builder.authorization("digest", zkConfig.getDigest().getBytes(StandardCharsets.UTF_8)).aclProvider(new ACLProvider() {

			@Override
			public List<ACL> getDefaultAcl() {
				return ZooDefs.Ids.CREATOR_ALL_ACL;
			}

			@Override
			public List<ACL> getAclForPath(final String path) {
				return ZooDefs.Ids.CREATOR_ALL_ACL;
			}
		});
	}
	client = builder.build();
	client.start();
	try {
		if (!client.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS)) {
			client.close();
			throw new KeeperException.OperationTimeoutException();
		}
	} catch (final Exception ex) {
		RegExceptionHandler.handleException(ex);
	}
}
 
開發者ID:imadcn,項目名稱:idworker,代碼行數:36,代碼來源:ZookeeperRegistryCenter.java

示例2: checkZk

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * Try to create a Zookeeper connection. Turns any exception encountered into a
 * KeeperException.OperationTimeoutException so it can retried.
 * @return The created Zookeeper connection object
 * @throws KeeperException
 */
protected synchronized ZooKeeper checkZk() throws KeeperException {
  if (this.zk == null) {
    try {
      this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher);
    } catch (IOException ex) {
      LOG.warn("Unable to create ZooKeeper Connection", ex);
      throw new KeeperException.OperationTimeoutException();
    }
  }
  return zk;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:18,代碼來源:RecoverableZooKeeper.java

示例3: init

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
@Override
public void init() {
    log.debug("Elastic job: zookeeper registry center init, server lists is: {}.", zkConfig.getServerLists());
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
            .connectString(zkConfig.getServerLists())
            .retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds()))
            .namespace(zkConfig.getNamespace());
    if (0 != zkConfig.getSessionTimeoutMilliseconds()) {
        builder.sessionTimeoutMs(zkConfig.getSessionTimeoutMilliseconds());
    }
    if (0 != zkConfig.getConnectionTimeoutMilliseconds()) {
        builder.connectionTimeoutMs(zkConfig.getConnectionTimeoutMilliseconds());
    }
    if (!Strings.isNullOrEmpty(zkConfig.getDigest())) {
        builder.authorization("digest", zkConfig.getDigest().getBytes(Charsets.UTF_8))
                .aclProvider(new ACLProvider() {
                
                    @Override
                    public List<ACL> getDefaultAcl() {
                        return ZooDefs.Ids.CREATOR_ALL_ACL;
                    }
                
                    @Override
                    public List<ACL> getAclForPath(final String path) {
                        return ZooDefs.Ids.CREATOR_ALL_ACL;
                    }
                });
    }
    client = builder.build();
    client.start();
    try {
        if (!client.blockUntilConnected(zkConfig.getMaxSleepTimeMilliseconds() * zkConfig.getMaxRetries(), TimeUnit.MILLISECONDS)) {
            client.close();
            throw new KeeperException.OperationTimeoutException();
        }
        //CHECKSTYLE:OFF
    } catch (final Exception ex) {
        //CHECKSTYLE:ON
        RegExceptionHandler.handleException(ex);
    }
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:42,代碼來源:ZookeeperRegistryCenter.java


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