0. retry policy
RetryPolicy retryPolicy = new ExponentialBackoffRetry(3000,3);
1. client
1) recipes
- org.apache.curator.framework.recipes.leader.LeaderSelector
- org.apache.curator.framework.recipes.cache.TreeCache
- org.apache.curator.framework.recipes.cache.PathChildrenCache
- org.apache.curator.x.discovery.ServiceDiscovery
2) CuratorFramework
- org.apache.curator.framework.CuratorFramework
(curator-frameworksrcmainjavaorgapachecuratorframeworkCuratorFramework.java)
2.create
curator-frameworksrcmainjavaorgapachecuratorframework
CuratorFrameworkFactory.java
1) simple
default:
CuratorFramework newClient(String connectString, RetryPolicy retryPolicy);
client.newClient("tdtc101:2181, tdtc102:2181, tdtc103:2181", retryPolicy);
advanced:
CuratorFramework newClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, RetryPolicy retryPolicy);
client.newClient("tdtc101:2181, tdtc102:2181, tdtc103:2181", 60 * 1000, 15 * 1000, retryPolicy);
2) Fluent style
default:
client = CuratorFrameworkFactory.builder()
.connectString("tdtc101:2181, tdtc102:2181, tdtc103:2181")
.retryPolicy(retryPolicy)
.build();
advanced:
client = CuratorFrameworkFactory.builder()
.connectString("tdtc101:2181, tdtc102:2181, tdtc103:2181")
.sessionTimeoutMs(60 * 1000) // CuratorFrameworkFactory.java Ln61
.connectionTimeoutMs(15 * 1000) // CuratorFrameworkFactory.java Ln62
.retryPolicy(retryPolicy)
.build();
3. start
client.start();