Java Code Examples for org.apache.curator.framework.CuratorFrameworkFactory.Builder#connectionTimeoutMs()
The following examples show how to use
org.apache.curator.framework.CuratorFrameworkFactory.Builder#connectionTimeoutMs() .
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: Test.java From hermes with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Builder builder = CuratorFrameworkFactory.builder(); builder.connectionTimeoutMs(1000); builder.connectString("127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183"); builder.retryPolicy(new RetryNTimes(1, 1000)); builder.sessionTimeoutMs(5000); CuratorFramework framework = builder.build(); framework.start(); try { framework.blockUntilConnected(); } catch (InterruptedException e) { throw new InitializationException(e.getMessage(), e); } System.in.read(); }
Example 2
Source File: ZKSuppportTestCase.java From hermes with Apache License 2.0 | 6 votes |
protected void configureCurator() throws Exception { Builder builder = CuratorFrameworkFactory.builder(); builder.connectionTimeoutMs(50); builder.connectString(getZkConnectionString()); builder.maxCloseWaitMs(50); builder.namespace("hermes"); builder.retryPolicy(new ExponentialBackoffRetry(5, 3)); builder.sessionTimeoutMs(50); m_curator = builder.build(); m_curator.start(); try { m_curator.blockUntilConnected(); } catch (InterruptedException e) { throw new InitializationException(e.getMessage(), e); } }
Example 3
Source File: MetaServerPrepareResourcesAndStart.java From x-pipe with Apache License 2.0 | 6 votes |
private CuratorFramework connectToZk(String connectString) throws InterruptedException { Builder builder = CuratorFrameworkFactory.builder(); builder.connectionTimeoutMs(3000); builder.connectString(connectString); builder.maxCloseWaitMs(3000); builder.namespace("xpipe"); builder.retryPolicy(new RetryNTimes(3, 1000)); builder.sessionTimeoutMs(5000); CuratorFramework client = builder.build(); client.start(); client.blockUntilConnected(); return client; }
Example 4
Source File: DefaultZkConfig.java From x-pipe with Apache License 2.0 | 6 votes |
@Override public CuratorFramework create(String address) throws InterruptedException { Builder builder = CuratorFrameworkFactory.builder(); builder.connectionTimeoutMs(getZkConnectionTimeoutMillis()); builder.connectString(address); builder.maxCloseWaitMs(getZkCloseWaitMillis()); builder.namespace(getZkNamespace()); builder.retryPolicy(new RetryNTimes(getZkRetries(), getSleepMsBetweenRetries())); builder.sessionTimeoutMs(getZkSessionTimeoutMillis()); builder.threadFactory(XpipeThreadFactory.create("Xpipe-ZK-" + address, true)); logger.info("[create]{}, {}", Codec.DEFAULT.encode(this), address); CuratorFramework curatorFramework = builder.build(); curatorFramework.start(); curatorFramework.blockUntilConnected(waitForZkConnectedMillis(), TimeUnit.MILLISECONDS); return curatorFramework; }
Example 5
Source File: ZKClient.java From hermes with Apache License 2.0 | 5 votes |
private void startCuratorFramework(ZookeeperEnsemble primaryEnsemble) throws InitializationException { Builder builder = CuratorFrameworkFactory.builder(); builder.connectionTimeoutMs(m_config.getZkConnectionTimeoutMillis()); builder.maxCloseWaitMs(m_config.getZkCloseWaitMillis()); builder.namespace(m_config.getZkNamespace()); builder.retryPolicy(new RetryNTimes(m_config.getZkRetries(), m_config.getSleepMsBetweenRetries())); builder.sessionTimeoutMs(m_config.getZkSessionTimeoutMillis()); builder.threadFactory(HermesThreadFactory.create("MetaService-Zk", true)); builder.ensembleProvider(new EnsembleProvider() { @Override public void start() throws Exception { } @Override public String getConnectionString() { return m_primaryZookeeperEnsemble.get().getConnectionString(); } @Override public void close() throws IOException { } }); m_client = builder.build(); m_client.start(); try { m_client.blockUntilConnected(); log.info("Conneted to zookeeper({}).", JSON.toJSONString(primaryEnsemble)); } catch (InterruptedException e) { throw new InitializationException(e.getMessage(), e); } }
Example 6
Source File: ZKClient.java From hermes with Apache License 2.0 | 5 votes |
private void startCuratorFramework(ZookeeperEnsemble primaryEnsemble) throws InitializationException { Builder builder = CuratorFrameworkFactory.builder(); builder.connectionTimeoutMs(m_config.getZkConnectionTimeoutMillis()); builder.maxCloseWaitMs(m_config.getZkCloseWaitMillis()); builder.namespace(m_config.getZkNamespace()); builder.retryPolicy(new RetryNTimes(m_config.getZkRetries(), m_config.getSleepMsBetweenRetries())); builder.sessionTimeoutMs(m_config.getZkSessionTimeoutMillis()); builder.threadFactory(HermesThreadFactory.create("Broker-Zk", true)); builder.ensembleProvider(new EnsembleProvider() { @Override public void start() throws Exception { } @Override public String getConnectionString() { return m_primaryZookeeperEnsemble.get().getConnectionString(); } @Override public void close() throws IOException { } }); m_client = builder.build(); m_client.start(); try { m_client.blockUntilConnected(); log.info("Conneted to zookeeper({}).", JSON.toJSONString(primaryEnsemble)); } catch (InterruptedException e) { throw new InitializationException(e.getMessage(), e); } }
Example 7
Source File: ZKClient.java From mpush with Apache License 2.0 | 4 votes |
/** * 初始化 */ @Override public void init() { if (client != null) return; if (zkConfig == null) { zkConfig = ZKConfig.build(); } Builder builder = CuratorFrameworkFactory .builder() .connectString(zkConfig.getHosts()) .retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMs(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepMs())) .namespace(zkConfig.getNamespace()); if (zkConfig.getConnectionTimeout() > 0) { builder.connectionTimeoutMs(zkConfig.getConnectionTimeout()); } if (zkConfig.getSessionTimeout() > 0) { builder.sessionTimeoutMs(zkConfig.getSessionTimeout()); } if (zkConfig.getDigest() != null) { /* * scheme对应于采用哪种方案来进行权限管理,zookeeper实现了一个pluggable的ACL方案,可以通过扩展scheme,来扩展ACL的机制。 * zookeeper缺省支持下面几种scheme: * * world: 默认方式,相当于全世界都能访问; 它下面只有一个id, 叫anyone, world:anyone代表任何人,zookeeper中对所有人有权限的结点就是属于world:anyone的 * auth: 代表已经认证通过的用户(cli中可以通过addauth digest user:pwd 来添加当前上下文中的授权用户); 它不需要id, 只要是通过authentication的user都有权限(zookeeper支持通过kerberos来进行authencation, 也支持username/password形式的authentication) * digest: 即用户名:密码这种方式认证,这也是业务系统中最常用的;它对应的id为username:BASE64(SHA1(password)),它需要先通过username:password形式的authentication * ip: 使用Ip地址认证;它对应的id为客户机的IP地址,设置的时候可以设置一个ip段,比如ip:192.168.1.0/16, 表示匹配前16个bit的IP段 * super: 在这种scheme情况下,对应的id拥有超级权限,可以做任何事情(cdrwa) */ builder.authorization("digest", zkConfig.getDigest().getBytes(Constants.UTF_8)); builder.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(); Logs.RSD.info("init zk client, config={}", zkConfig.toString()); }