zookeeper C API
typedef void (*watcher_fn)(zhandle_t *zh, int type, int state, const char *path,void *watcherCtx);
watch回调函数,两种watch事件通知方式:
1.legacy:预先实现watch回调函数并将函数指针传入zookeeper_init,然后使用其他api设置watch。 (即在init函数中设置watcher,然后后边调用时,设置整型值watch来表明使用或者不使用watcher)
2.watcher object:一个函数指针和一个watcher上下文指针。watch触发时,两者结合调用。使用此类型,需使用'w'前缀api,如zoo_awexists、zoo_wget等.(直接使用回调函数)
zhandle_t *zookeeper_init(const char *host, watcher_fn fn, int recv_timeout, const clientid_t *clientid, void *context, int flags);
创建与ZooKeeper服务端通信的句柄和对应于此句柄的会话。会话的创建过程是异步的,收到ZOO_CONNECTED_STATE状态事件后,确认会话成功建立。 int zookeeper_close(zhandle_t *zh);
关闭句柄,释放资源。调用函数后,会话将不可用,函数返回前会将未发送完毕的请求发送完,所以可能会引起阻塞。
对一个句柄来说,这个方法只许调用一次,调用多次将产生不确定的结果。对于调用过此方法的句柄,其他句柄操作也将产生不确定的结果。 const clientid_t *zoo_client_id(zhandle_t *zh);
返回客户端会话id,仅在与服务端连接正常时有效 int zoo_recv_timeout(zhandle_t *zh);
返回会话超时时间,仅在于服务端连接正常时有效,该值在与服务器重连后可能改变 const void *zoo_get_context(zhandle_t *zh);
返回句柄上下文 void zoo_set_context(zhandle_t *zh, void *context);
设置句柄上下文 watcher_fn zoo_set_watcher(zhandle_t *zh,watcher_fn newFn);
设置watch回调,返回之前的watch回调 struct sockaddr* zookeeper_get_connected_host(zhandle_t *zh, struct sockaddr *addr, socklen_t *addr_len);
返回服务端的网络地址(sockaddr结构),仅在与服务端连接正常是有效 int zookeeper_interest(zhandle_t *zh, int *fd, int *interest, struct timeval *tv);
暂时不太理解,可能是返回zookeeper在监听某个fd的读或者写 int zookeeper_process(zhandle_t *zh, int events);
暂时不太理解,通知zookeeper监听的事件发生了 typedef void (*void_completion_t)(int rc, const void *data);
函数类型定义,异步调用或连接断开或连接超时执行的回调类型 typedef void (*stat_completion_t)(int rc, const struct Stat *stat, const void *data);
同上,有返回值 typedef void (*data_completion_t)(int rc, const char *value, int value_len, const struct Stat *stat, const void *data);
同上,返回详细数据 typedef void (*strings_completion_t)(int rc, const struct String_vector *strings, const void *data);
同上 typedef void (*strings_stat_completion_t)(int rc, const struct String_vector *strings, const struct Stat *stat, const void *data);
同上 typedef void (*string_completion_t)(int rc, const char *value, const void *data);
同上 typedef void (*acl_completion_t)(int rc, struct ACL_vector *acl, struct Stat *stat, const void *data);
同上 int zoo_state(zhandle_t *zh);
返回句柄状态 int zoo_acreate(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, string_completion_t completion, const void *data);
创建一个之前不存在的节点。如果设置ZOO_EPHEMERAL,客户端会话失效,节点将自动删除;如果设置ZOO_SEQUENCE,一个唯一的自动增加的序列号附加到路径名,序列号宽度是10个数字的宽度,不足用0填充 int zoo_adelete(zhandle_t *zh, const char *path, int version, void_completion_t completion, const void *data);
删除一个节点 int zoo_aexists(zhandle_t *zh, const char *path, int watch, stat_completion_t completion, const void *data);
检查一个节点是否存在 int zoo_awexists(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, stat_completion_t completion, const void *data);
检查一个节点是否存在,它允许指定一个watcher对象(一个函数指针watcher和对应的上下文watcherCtx),在watch解除时,此函数会调用,watcherCtx作为watcher的传入参数 int zoo_aget(zhandle_t *zh, const char *path, int watch, data_completion_t completion, const void *data);
获取节点数据(legacy方式)。completion是回调函数,其rc参数可能是以下参数:ZOK-完成,ZNONODE-节点不存在,ZNOAUTH-客户端无权限 int zoo_awget(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, data_completion_t completion, const void *data);
获取节点数据(watcher object方式)。 int zoo_aset(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version, stat_completion_t completion, const void *data);
设置节点数据 int zoo_aget_children(zhandle_t *zh, const char *path, int watch, strings_completion_t completion, const void *data);
获取子节点列表(legacy) int zoo_awget_children(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, strings_completion_t completion, const void *data);
获取子节点列表(watcher object) int zoo_aget_children2(zhandle_t *zh, const char *path, int watch, strings_stat_completion_t completion, const void *data);
获取子节点列表,3.3.0版本加入(legacy) int zoo_awget_children2(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, strings_stat_completion_t completion, const void *data);
获取子节点列表,3.3.0版本加入(watcher object) int zoo_async(zhandle_t *zh, const char *path, string_completion_t completion, const void *data);
Flush leader channel. 暂时不明确 int zoo_aget_acl(zhandle_t *zh, const char *path, acl_completion_t completion, const void *data);
获取节点的ACL。ACL描述了操作该节点所需具备的条件,即哪些人(id)具备哪些权限后才允许对节点执行哪些操作。 int zoo_aset_acl(zhandle_t *zh, const char *path, int version, struct ACL_vector *acl, void_completion_t, const void *data);
设置节点的ACL int zoo_amulti(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results, void_completion_t, const void *data);
以原子方式执行一系列操作 const char* zerror(int c);
返回错误信息 int zoo_add_auth(zhandle_t *zh, const char* scheme, const char* cert, int certLen, void_completion_t completion, const void *data);
为应用程序指定证书。调用此函数用于认证的证书。服务端用scheme指定的安全服务对客户端连接进行认证。
如果认证失败,将与服务端断开连接,watcher触发,状态码是ZOO_AUTH_FAILED_STATE int is_unrecoverable(zhandle_t *zh);
检查zookeeper连接是否可恢复 void zoo_set_debug_level(ZooLogLevel logLevel);
设置调试级别 void zoo_set_log_stream(FILE* logStream);
设置用于记录日志的文件流。默认使用stderr。若logStream为NULL,则使用默认值stderr。 void zoo_deterministic_conn_order(int yesOrNo);
用于启用或停用quarum端点的随机化排序,通常仅在测试时使用。
如果非0,使得client连接到quarum端按照被初始化的顺序。
如果是0,zookeeper_init将变更端点顺序,使得client连接分布在更优的端点上。 int zoo_create(zhandle_t *zh, const char *path, const char *value, int valuelen, const struct ACL_vector *acl, int flags, char *path_buffer, int path_buffer_len);
同步建立节点 int zoo_delete(zhandle_t *zh, const char *path, int version);
同步删除节点 int zoo_exists(zhandle_t *zh, const char *path, int watch, struct Stat *stat);
同步检查节点是否存在 int zoo_wexists(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, struct Stat *stat);
同步检查节点是否存在(watcher object) int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, int* buffer_len, struct Stat *stat);
同步获取节点数据(legacy) int zoo_wget(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, char *buffer, int* buffer_len, struct Stat *stat);
同步获取节点数据(watcher object) int zoo_set(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version);
同步设置节点数据 int zoo_set2(zhandle_t *zh, const char *path, const char *buffer, int buflen, int version, struct Stat *stat);
同步设置节点数据并返回当前节点的stat信息 int zoo_get_children(zhandle_t *zh, const char *path, int watch, struct String_vector *strings);
同步获取子节点列表(legacy) int zoo_wget_children(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, struct String_vector *strings);
同步获取子节点列表(watcher object) int zoo_get_children2(zhandle_t *zh, const char *path, int watch, struct String_vector *strings, struct Stat *stat);
同步获取子节点列表并返回当前节点的stat信息(legacy),3.3.0版本加入 int zoo_wget_children2(zhandle_t *zh, const char *path, watcher_fn watcher, void* watcherCtx, struct String_vector *strings, struct Stat *stat);
同步获取子节点列表并返回当前节点的stat信息(watcher object),3.3.0版本加入 int zoo_get_acl(zhandle_t *zh, const char *path, struct ACL_vector *acl, struct Stat *stat);
同步获取节点ACL int zoo_set_acl(zhandle_t *zh, const char *path, int version, const struct ACL_vector *acl);
同步设置节点ACL int zoo_multi(zhandle_t *zh, int count, const zoo_op_t *ops, zoo_op_result_t *results);
同步以原子方式执行一系列操作
说明:keeper C API 大部分接口可以根据同步和异步特性分为两类,同步接口以 zoo_* 开头,异步接口以则以 zoo_a* 开头。以w开头的函数表明使用watcher回调函数而不是整型watch和zookeeper中注册的watcher函数。
转自 : http://www.cnblogs.com/caosiyang/archive/2012/11/09/2763190.html
zookeeper C API的更多相关文章
- (原) 2.1 Zookeeper原生API使用
本文为原创文章,转载请注明出处,谢谢 Zookeeper原生API使用 1.jar包引入,演示版本为3.4.6,非maven项目,可以下载jar包导入到项目中 <dependency> & ...
- Zookeeper C API 指南四(C API 概览)(转)
上一节<Zookeeper C API 指南三(回调函数)>重点讲了 Zookeeper C API 中各种回调函数的原型,本节将切入正题,正式讲解 Zookeeper C API.相信大 ...
- Zookeeper C API 指南三(回调函数)(转)
2013-02-21 12:54 by Haippy, 9237 阅读, 0 评论, 收藏, 编辑 接上一篇<Zookeeper C API 指南二(监视(Wathes), 基本常量和结构体介绍 ...
- Zookeeper C API 指南一(转)
Zookeeper 监视(Watches) 简介 Zookeeper C API 的声明和描述在 include/zookeeper.h 中可以找到,另外大部分的 Zookeeper C API 常量 ...
- zookeeper client API实现(python kazoo 的实现)
这里主要分析zookeeper client API的实现方式,以python kazoo的实现代码为蓝本进行逻辑分析. 一.代码框架及介绍 API分为同步模式和异步模式.同步模式是在异步模式的基础上 ...
- 9. 使用ZooKeeper Java API编程
ZooKeeper是用Java开发的,3.4.6版本的Java API文档可以在http://zookeeper.apache.org/doc/r3.4.6/api/index.html上找到. Ti ...
- Zookeeper系列三:Zookeeper客户端的使用(Zookeeper原生API如何进行调用、ZKClient、Curator)和Zookeeper会话
一.Zookeeper原生API如何进行调用 准备工作: 首先在新建一个maven项目ZK-Demo,然后在pom.xml里面引入zk的依赖 <dependency> <groupI ...
- Hadoop生态圈-zookeeper的API用法详解
Hadoop生态圈-zookeeper的API用法详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.测试前准备 1>.开启集群 [yinzhengjie@s101 ~] ...
- zookeeper原生API做java客户端
简介 本文是使用apache提供的原生api做zookeeper客户端 jar包 zookeeper-3.4.5.jar Demo package bjsxt.zookeeper.base; im ...
- Zookeeper Curator API 使用
0. 原生 ZOOKEEPER JAVA API http://www.cnblogs.com/rocky-fang/p/9030438.html 1. 概述 Curator采用cache封装对事件 ...
随机推荐
- C++primer 9.49
题目:如果一个字母延伸到中线之上,如d或f,则称其有上出头部分(ascender).如果一个字母延伸到中线之下,如p或g,则称其有下出头部分(descender).编写程序,读入一个单词文件,输出最长 ...
- find the greatest common divisor
function gcd(a, b) return a else return gcd(b, a mod b)
- UIImageView的UserInteractionEnabled什么时候为no
UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件 特殊子类的覆盖 userInteractionEnabled属性默认值为YES,但UIView的一些子类中对 ...
- Linux系统故障处理案例(一)【转】
2016-08-05 14:41 运行环境:CentOS6.7 故障原因: 昨天在线执行命令yum -y update 在命令执行途中,强制中断并直接运行poweroff命令关机.再次开机出现如图所示 ...
- UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-15: ordinal not in range(128)
python在安装时,默认的编码是ascii,当程序中出现非ascii编码时,python的处理常常会报类似这样的错误. UnicodeEncodeError: 'ascii' codec can't ...
- 使用composer命令创建laravel项目命令详解
composer命令创建laravel项目的命令是: composer create-project --prefer-dist laravel/laravel blog "5.2.*&qu ...
- Inno Setup入门(二十)——Inno Setup类参考(6)
存储框 存储框也是典型的窗口可视化组件,同编辑框类似,可以输入.显示文本,但是和编辑框不同的是,编辑框只能编辑.显示单行文本,而存储框则可以对多行文本进行操作.存储框的类定义如下:< xmlna ...
- java中怎么解决路径中文的问题
在我遇到精灵线程的问题时,遇到一个中文路径的问题 原来是这样的 URL url=Test8.class.getClassLoader().getResource(""); Stri ...
- 字符函数库 cctype
<cctype> (ctype.h) Character handling functions This header declares a set of functions to cla ...
- div+css网页本地上和上传到服务器后在IE11上看到的效果不一样?
div+css网页本地上和上传到服务器后在IE11上看到的效果不一样? 解决办法在html的head里加上一段:<meta http-equiv="X-UA-Compatible&qu ...