ZooKeeper类说明
ZooKeeper 类是ZooKeeper 客户端库的主要类。要使用ZooKeeper服务,应用程序必须首先实例化ZooKeeper类的对象。所有的迭代都将通过调用ZooKeeper类的方法来完成。除非另有说明,否则此类的方法是线程安全的。
一旦建立到服务器的连接,会话ID就分配给客户机。客户机将定期向服务器发送心跳以保持会话有效。
只要客户端的会话ID保持有效,应用程序就可以通过客户端调用ZooKeeper API。
如果由于某种原因,客户机在很长一段时间内(例如超过sessionTimeout值)无法向服务器发送心跳,服务器将使会话过期,会话ID将变为无效。客户端对象将不再可用。要进行ZooKeeper API调用,应用程序必须创建一个新的客户机对象。
如果客户机当前连接到的ZooKeeper服务器出现故障或没有响应,客户机将在其会话ID过期之前自动尝试连接到其他服务器。如果成功,应用程序可以继续使用客户端。
ZooKeeper API方法要么是同步的,要么是异步的。同步方法会一直阻塞,直到服务器响应为止。异步方法只是将发送请求排队,然后立即返回。它们接受一个回调对象,该对象将在成功执行请求或出错时执行,返回代码(rc)指示错误。
一些成功的ZooKeeper API调用可以将监视留在ZooKeeper服务器的“数据节点”上。其他成功的ZooKeeper API调用可以触发这些监视。一旦一个手表被触发,一个事件将被传递给客户机,客户机首先离开了手表。每个表只能触发一次。因此,每离开一只手表,最多会向客户发送一个事件。
客户机需要一个实现观察程序接口的类的对象来处理传递给客户机的事件。当客户机断开当前连接并重新连接到服务器时,所有现有的监视都被认为是被触发的,但未传递的事件将丢失。为了模拟这一点,客户机将生成一个特殊的事件来告诉事件处理程序连接已经断开。此特殊事件具有类型eventnone和状态skeeperstatedisconnected。
This is the main class of ZooKeeper client library. To use a ZooKeeper service, an application must first instantiate an object of ZooKeeper class. All the iterations will be done by calling the methods of ZooKeeper class. The methods of this class are thread-safe unless otherwise noted.
Once a connection to a server is established, a session ID is assigned to the client. The client will send heart beats to the server periodically to keep the session valid.
The application can call ZooKeeper APIs through a client as long as the session ID of the client remains valid.
If for some reason, the client fails to send heart beats to the server for a prolonged period of time (exceeding the sessionTimeout value, for instance), the server will expire the session, and the session ID will become invalid. The client object will no longer be usable. To make ZooKeeper API calls, the application must create a new client object.
If the ZooKeeper server the client currently connects to fails or otherwise does not respond, the client will automatically try to connect to another server before its session ID expires. If successful, the application can continue to use the client.
The ZooKeeper API methods are either synchronous or asynchronous. Synchronous methods blocks until the server has responded. Asynchronous methods just queue the request for sending and return immediately. They take a callback object that will be executed either on successful execution of the request or on error with an appropriate return code (rc) indicating the error.
Some successful ZooKeeper API calls can leave watches on the "data nodes" in the ZooKeeper server. Other successful ZooKeeper API calls can trigger those watches. Once a watch is triggered, an event will be delivered to the client which left the watch at the first place. Each watch can be triggered only once. Thus, up to one event will be delivered to a client for every watch it leaves.
A client needs an object of a class implementing Watcher interface for processing the events delivered to the client. When a client drops current connection and re-connects to a server, all the existing watches are considered as being triggered but the undelivered events are lost. To emulate this, the client will generate a special event to tell the event handler a connection has been dropped. This special event has type EventNone and state sKeeperStateDisconnected.
ZooKeeper类说明的更多相关文章
- rabbitMq实现与zookeeper类似的watcher功能
场景:A.B.C.D(可以是一个机器的不同进程,也可以是不同机器的进程)启动了相同的项目,使用同一个数据库.但是,如果A修改了数据库的数据,需要B.C.D在很短的时间能够知道数据库发生了修改.当然可以 ...
- Zookeeper开源客户端框架Curator简介
Curator是Netflix开源的一套ZooKeeper客户端框架. Netflix在使用ZooKeeper的过程中发现ZooKeeper自带的客户端太底层, 应用方在使用的时候需要自己处理很多事情 ...
- Zookeeper Api(java)入门与应用(转)
如何使用 Zookeeper 作为一个分布式的服务框架,主要用来解决分布式集群中应用系统的一致性问题,它能提供基于类似于文件系统的目录节点树方式的数据存储,但是 Zookeeper 并不是用来专门存储 ...
- 转载:ZooKeeper Programmer's Guide(中文翻译)
本文是为想要创建使用ZooKeeper协调服务优势的分布式应用的开发者准备的.本文包含理论信息和实践信息. 本指南的前四节对各种ZooKeeper概念进行较高层次的讨论.这些概念对于理解ZooKeep ...
- 分布式服务框架Zookeeper
协议介绍 zookeeper协议分为两种模式 崩溃恢复模式和消息广播模式 崩溃恢复协议是在集群中所选举的leader 宕机或者关闭 等现象出现 follower重新进行选举出新的leader 同时集群 ...
- Zookeeper集群的安装和使用
Apache Zookeeper 由 Apache Hadoop 的 Zookeeper 子项目发展而来,现已经成为 Apache 的顶级项目,它是一个开放源码的分布式应用程序协调服务,是Google ...
- 分布式服务框架 Zookeeper -- 管理分布式环境中的数据
转自:http://www.ibm.com/developerworks/cn/opensource/os-cn-zookeeper/index.html Zookeeper 分布式服务框架是 Apa ...
- ZooKeeper程序员指南(转)
译自http://zookeeper.apache.org/doc/trunk/zookeeperProgrammers.html 1 简介 本文是为想要创建使用ZooKeeper协调服务优势的分布式 ...
- Zookeeper开源客户端框架Curator简介[转]
Curator是Netflix开源的一套ZooKeeper客户端框架. Netflix在使用ZooKeeper的过程中发现ZooKeeper自带的客户端太底层, 应用方在使用的时候需要自己处理很多事情 ...
随机推荐
- PHP采集类:Snoopy.class.php
Snoopy是一个php采集类,用来模拟浏览器获取网页内容和发送表单. 下面是一些Snoopy特性: 容易抓取网页内容 容易抓取页面文本(去除HTML标签) 容易抓取网页内链接 支持代理抓取 支持基本 ...
- python3获取天气预报
#!/usr/local/bin/python3 #coding=utf-8 ''' Created on 2011-2-25 @author: http://www.cnblogs.com/txw1 ...
- 阿凡达是脸,教你的脸在线(包括URL和使用)
官方网站:http://www.mcdonalds.at/avatar/ 英文版本号:lid=finland" target="_blank">http://www ...
- LAN公布java web项目的方法的外侧
1.进入路由器设置页面:http://192.168.1.1 2.找到"转发规则"选项,我现在的路由器tp-link,不同型号tp-link"转发规则"选项位置 ...
- 通过.NET客户端调用Web API(C#)
3.2 Calling a Web API From a .NET Client (C#) 3.2 通过.NET客户端调用Web API(C#) 本文引自:http://www.asp.net/web ...
- linux虚拟机上svn客户端连接问题
在虚拟机上搭建好的svn,本地连接居然不行,原来是防火墙端口没开造成的. 修改配置文件:vi /etc/sysconfig/iptables # Generated by iptables-save ...
- 高手问答精选:Go 语言 —— 云计算时代的 C 语言(类似于一个FAQ)
Go 语言被称为云计算时代的 C 语言,它在软件开发效率和运行效率之间做出了绝佳的权衡.这使得它既适应于互联网应用的极速开发,又能在高并发.高性能的开发场景中如鱼得水.正因如此,许多互联网公司,尤其是 ...
- 新浪API登录实例
步骤一:添加网站 进入新浪微博开放平台,http://open.weibo.com/apps 进入“管理中心“,点击”创建应用”,选择“网页应用”,填写相应的信息后提交. 步骤二:Oauth2.0授权 ...
- Win8Metro(C#)数字图像处理--2.6图像对比度调整
原文:Win8Metro(C#)数字图像处理--2.6图像对比度调整 2.6图像对比度调整函数 [函数名称] 图像对比度调整函数ContrastAdjustProcess(WriteableBi ...
- GIS基础软件及操作(二)
原文 GIS基础软件及操作(二) 练习二.管理地理空间数据库 1.利用ArcCatalog 管理地理空间数据库 2.在ArcMap中编辑属性数据 第1步 启动 ArcCatalog 打开一个地理数据库 ...