Java Code Examples for org.apache.zookeeper.KeeperException#OperationTimeoutException
The following examples show how to use
org.apache.zookeeper.KeeperException#OperationTimeoutException .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeZookeeperRegistryCenter.java From opensharding-spi-impl with Apache License 2.0 | 6 votes |
private IZookeeperClient initClient(final ClientFactory clientFactory, final RegistryCenterConfiguration config) { IZookeeperClient result = null; try { // TODO There is a bug when the start time is very short, and I haven't found the reason yet // result = clientFactory.start(config.getRetryIntervalMilliseconds() * config.getMaxRetries(), TimeUnit.MILLISECONDS); result = clientFactory.start(); if (!result.blockUntilConnected(config.getRetryIntervalMilliseconds() * config.getMaxRetries(), TimeUnit.MILLISECONDS)) { result.close(); throw new KeeperException.OperationTimeoutException(); } result.useExecStrategy(StrategyType.SYNC_RETRY); } catch (final KeeperException.OperationTimeoutException | IOException | InterruptedException ex) { NativeZookeeperExceptionHandler.handleException(ex); } return result; }
Example 2
Source File: RecoverableZooKeeper.java From hbase with Apache License 2.0 | 5 votes |
/** * 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 if a ZooKeeper operation fails */ 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; }
Example 3
Source File: ZookeeperRegistryCenter.java From paascloud-master with Apache License 2.0 | 4 votes |
/** * Init. */ @Override public void init() { log.debug("Elastic job: zookeeper registry center init, server lists is: {}.", zkConfig.getZkAddressList()); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(zkConfig.getZkAddressList()) .retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds())); 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); } }
Example 4
Source File: ZookeeperRegistryCenter.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 4 votes |
@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); } }
Example 5
Source File: ZookeeperRegistryCenter.java From eagle with Apache License 2.0 | 4 votes |
@Override public void init() { if (!stat.compareAndSet(false, true)) { return; } String address = registryConfig.getExt(ConfigEnum.address.getName(), ConfigEnum.address.getValue()); logger.info("zookeeper registry center init, server lists is: {}.", address); String namespace = registryConfig.getExt(ConfigEnum.namespace.getName(), ConfigEnum.namespace.getValue()); int baseSleepTimeMilliseconds = registryConfig.getExtInt(ConfigEnum.baseSleepTimeMilliseconds.getName(), ConfigEnum.baseSleepTimeMilliseconds.getIntValue()); int maxSleepTimeMilliseconds = registryConfig.getExtInt(ConfigEnum.maxSleepTimeMilliseconds.getName(), ConfigEnum.maxSleepTimeMilliseconds.getIntValue()); int maxRetries = registryConfig.getExtInt(ConfigEnum.maxRetries.getName(), ConfigEnum.maxRetries.getIntValue()); int sessionTimeoutMilliseconds = registryConfig.getExtInt(ConfigEnum.sessionTimeoutMilliseconds.getName(), ConfigEnum.sessionTimeoutMilliseconds.getIntValue()); int connectionTimeoutMilliseconds = registryConfig.getExtInt(ConfigEnum.connectionTimeoutMilliseconds.getName(), ConfigEnum.connectionTimeoutMilliseconds.getIntValue()); String digest = registryConfig.getExt(ConfigEnum.digest.getName(), ConfigEnum.digest.getValue()); CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder() .connectString(address) .retryPolicy(new ExponentialBackoffRetry(baseSleepTimeMilliseconds, maxRetries, maxSleepTimeMilliseconds)) .namespace(namespace); if (0 != sessionTimeoutMilliseconds) { builder.sessionTimeoutMs(sessionTimeoutMilliseconds); } if (0 != connectionTimeoutMilliseconds) { builder.connectionTimeoutMs(connectionTimeoutMilliseconds); } if (!Strings.isNullOrEmpty(digest)) { builder.authorization("digest", digest.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 { client.blockUntilConnected(maxSleepTimeMilliseconds * maxRetries, TimeUnit.MILLISECONDS); if (!client.getZookeeperClient().isConnected()) { client.close(); throw new KeeperException.OperationTimeoutException(); } //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON throw new EagleFrameException(ex); } }
Example 6
Source File: ZookeeperRegistryCenter.java From idworker with Apache License 2.0 | 4 votes |
@Override public synchronized void init() { if (client != null) { // client已经初始化,直接重置返回 return; } 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); } }
Example 7
Source File: ZookeeperRegistryCenter.java From shardingsphere-elasticjob-lite with Apache License 2.0 | 4 votes |
@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); } }
Example 8
Source File: BaseClientFactory.java From opensharding-spi-impl with Apache License 2.0 | 3 votes |
/** * Start until Timeout. * * @param waitingTime waiting time * @param timeUnit time unit * @return connected or not * @throws IOException IO Exception * @throws InterruptedException interrupted exception * @throws KeeperException operation timeout exception */ public IZookeeperClient start(final int waitingTime, final TimeUnit timeUnit) throws IOException, InterruptedException, KeeperException { prepareClient(); if (!client.start(waitingTime, timeUnit)) { client.close(); throw new KeeperException.OperationTimeoutException(); } return client; }