Curator Framework
Framework 比较简单,就是一些CRUD,Watch :
package curator.framework; import java.util.List; import org.apache.curator.RetryPolicy; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.zookeeper.CreateMode; public class FrameworkDemo { public static void main(String[] args) { connection1(); } private static void connection1() { RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework client = CuratorFrameworkFactory.builder() .connectString("127.0.0.1:2181") .sessionTimeoutMs(5000) .connectionTimeoutMs(10000) .retryPolicy(retryPolicy) .namespace("text").build(); client.start(); try { byte[] b = null; // 创建 client.create().withMode(CreateMode.EPHEMERAL).forPath("/xx",new String("").getBytes()); // 得到值 client.getData().forPath(""); // 得到子节点 List<String> List<String> ls = client.getChildren().forPath(""); // 删除 client.delete().forPath(""); // 修改 client.setData().forPath("", b); } catch (Exception e) { } client.close(); } private static void connection2() { RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3); CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy); client.start(); client.close(); } }
相关推荐
duckes 2020-05-25
亦碎流年 2020-02-19
wangyangsoftware 2019-12-17
hyclq 2018-12-24
strburnchang 2016-01-09
Wisher 2019-07-01
XiaoqiangNan 2018-12-24
huangliuyu00 2019-06-29
田雄兵 2014-03-03
dinux 2014-03-03
bloodsuckerm 2018-09-29
yixu0 2018-08-17
zcanxue 2019-04-30
加号Jaryn笔录 2016-09-13