Java Code Examples for org.apache.curator.framework.CuratorFrameworkFactory.Builder#retryPolicy()

The following examples show how to use org.apache.curator.framework.CuratorFrameworkFactory.Builder#retryPolicy() . 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 vote down vote up
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 vote down vote up
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 vote down vote up
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 vote down vote up
@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 vote down vote up
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 vote down vote up
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);
	}
}