当前位置: 首页>>代码示例>>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;未经允许,请勿转载。