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的更多相关文章

  1. (原) 2.1 Zookeeper原生API使用

    本文为原创文章,转载请注明出处,谢谢 Zookeeper原生API使用 1.jar包引入,演示版本为3.4.6,非maven项目,可以下载jar包导入到项目中 <dependency> & ...

  2. Zookeeper C API 指南四(C API 概览)(转)

    上一节<Zookeeper C API 指南三(回调函数)>重点讲了 Zookeeper C API 中各种回调函数的原型,本节将切入正题,正式讲解 Zookeeper C API.相信大 ...

  3. Zookeeper C API 指南三(回调函数)(转)

    2013-02-21 12:54 by Haippy, 9237 阅读, 0 评论, 收藏, 编辑 接上一篇<Zookeeper C API 指南二(监视(Wathes), 基本常量和结构体介绍 ...

  4. Zookeeper C API 指南一(转)

    Zookeeper 监视(Watches) 简介 Zookeeper C API 的声明和描述在 include/zookeeper.h 中可以找到,另外大部分的 Zookeeper C API 常量 ...

  5. zookeeper client API实现(python kazoo 的实现)

    这里主要分析zookeeper client API的实现方式,以python kazoo的实现代码为蓝本进行逻辑分析. 一.代码框架及介绍 API分为同步模式和异步模式.同步模式是在异步模式的基础上 ...

  6. 9. 使用ZooKeeper Java API编程

    ZooKeeper是用Java开发的,3.4.6版本的Java API文档可以在http://zookeeper.apache.org/doc/r3.4.6/api/index.html上找到. Ti ...

  7. Zookeeper系列三:Zookeeper客户端的使用(Zookeeper原生API如何进行调用、ZKClient、Curator)和Zookeeper会话

    一.Zookeeper原生API如何进行调用 准备工作: 首先在新建一个maven项目ZK-Demo,然后在pom.xml里面引入zk的依赖 <dependency> <groupI ...

  8. Hadoop生态圈-zookeeper的API用法详解

    Hadoop生态圈-zookeeper的API用法详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.测试前准备 1>.开启集群 [yinzhengjie@s101 ~] ...

  9. zookeeper原生API做java客户端

    简介 本文是使用apache提供的原生api做zookeeper客户端 jar包 zookeeper-3.4.5.jar   Demo package bjsxt.zookeeper.base; im ...

  10. Zookeeper Curator API 使用

    0. 原生 ZOOKEEPER JAVA API  http://www.cnblogs.com/rocky-fang/p/9030438.html 1. 概述 Curator采用cache封装对事件 ...

随机推荐

  1. time_t

    所在的头文件为 time.h 定义为: #ifndef __TIME_T #define __TIME_T     /* 避免重复定义 time_t */ typedef long     time_ ...

  2. Storm官方文档翻译之在生产环境集群中运行Topology

    在进群生产环境下运行Topology和在本地模式下运行非常相似.下面是步骤: 1.定义Topology(如果使用Java开发语言,则使用TopologyBuilder来创建) 2.使用StormSub ...

  3. UIImageView的UserInteractionEnabled什么时候为no

    UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件 特殊子类的覆盖 userInteractionEnabled属性默认值为YES,但UIView的一些子类中对 ...

  4. 遭遇mediumint上限

    Mediumint:The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215. home_notific ...

  5. 删除sql计划 调用的目标发生了异常。 (mscorlib) 其他信息: 用户 'sa' 登录失败。

    在删除以前创建的sql的计划任务时,弹出如题错误提示,发现错误原因在于,sa密码更改过,导致在删除时因为sa的密码和当前的密码不正确出现此错误. 解决办法: 1.在计划任务的编辑窗口,找到管理连接 2 ...

  6. IntelliJ IDEA 2016.1.3激活【亲测可用】

    测试日期:2016.6.24 License server: http://www.iteblog.com/idea/key.php // ========================= 更多技术 ...

  7. error: invalid 'asm': invalid operand for code 'w'

    google 出结果 http://stackoverflow.com/questions/15623609/including-curl-into-the-android-aosp ........ ...

  8. 【转】Git代码行统计命令集

    http://blog.csdn.NET/dwarven/article/details/46550117 http://blog.csdn.net/hshl1214/article/details/ ...

  9. 转 Linux下的GoldenGate的启动关闭Shell脚本(独立)

    用户想要用OGG进行同步数据,原来用的是Shareplex,至于为啥要换OGG,BulaBula一堆原因.....这不是我们要在意的事情,和客 户装完配置好OGG之后,测试中,客户提出要有个简单的启动 ...

  10. 转 : net use的使用

    老是忘了 net use 怎么样,今天在网上找一篇,贴在这,感谢原作者分享.     1 查看远程主机的共享资源(但看不到默认共享) net view \\IP 2向远程主机复制文件 copy \路径 ...