Zookeeper实例Curator API-使用Fluent风格的API接口来创建一个ZooKeeper客户端

来源:互联网 发布:多益网络校招笔试题 编辑:程序博客网 时间:2024/05/17 04:23


/** *  * @ClassName: Create_Session_Sample_fluent * @Description: TODO(使用Fluent风格的API接口来创建一个ZooKeeper客户端) * @author RongShu * @date 2017年6月17日 上午9:46:35 * */public class Create_Session_Sample_fluent {public static void main(String[] args) throws Exception {RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);CuratorFramework client = CuratorFrameworkFactory.builder().connectString("localhosts:2181").sessionTimeoutMs(5000).retryPolicy(retryPolicy).build();client.start();Thread.sleep(Integer.MAX_VALUE);}}


注意:

Curator提供的API接口在设计商最大的亮点在于遵循了Fluent设计风格,这也是和Zookeeper原生API以及ZkClient客户端有很大的不同地方。


参考

1.《从Paxos到Zookeeper:分布式一致性原理与实践》

2. http://curator.apache.org/apidocs/

阅读全文
0 0