Curator教程(一)watcher监听

1.watcher方式一(监听当前节点发生变更)

成都创新互联一直通过网站建设和网站营销帮助企业获得更多客户资源。 以"深度挖掘,量身打造,注重实效"的一站式服务,以成都网站建设、网站建设、移动互联产品、全网整合营销推广服务为核心业务。十多年网站制作的经验,使用新网站建设技术,全新开发出的标准网站,不但价格便宜而且实用、灵活,特别适合中小公司网站制作。网站管理系统简单易用,维护方便,您可以完全操作网站资料,是中小公司快速网站建设的选择。

		String address = "mini1:2181,mini2:2181,mini3:2181";
		 RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 10);
		 
		CuratorFramework client = CuratorFrameworkFactory.newClient(address, new ExponentialBackoffRetry(1000, 3));
		
		client.start();
		
		//创建节点watcher监听
		 final NodeCache cache = new NodeCache(client, "/super", false);
		 cache.start(true);
		 cache.getListenable().addListener(new NodeCacheListener() {
			
			public void nodeChanged() throws Exception {
				System.out.println(cache.getCurrentData().getPath());
				System.out.println(cache.getCurrentData().getStat());
			}
		});

2.watcher方式二(监听当前节点的子节点发生变更)

		String address = "mini1:2181,mini2:2181,mini3:2181";
		 RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 10);
		 
		CuratorFramework client = CuratorFrameworkFactory.newClient(address, new ExponentialBackoffRetry(1000, 3));
		
		client.start();
	
		//创建子节点watcher监听
		 PathChildrenCache cache = new PathChildrenCache(client, "/super", true);
		 cache.start(StartMode.POST_INITIALIZED_EVENT);
		 cache.getListenable().addListener(new PathChildrenCacheListener() {
			public void childEvent(CuratorFramework cf, PathChildrenCacheEvent event) throws Exception {
				System.out.println(event.getType());
			}
		});
		 Thread.sleep(Long.MAX_VALUE);

网页名称:Curator教程(一)watcher监听
文章地址:https://www.cdcxhl.com/article8/ppjeop.html

成都网站建设公司_创新互联,为您提供关键词优化网站制作外贸建站网站维护域名注册手机网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计