ZooKeeper - Perl bindings for Apache ZooKeeper  Perl绑定用于 Apache ZooKeeper

监控 master/slave 需要使用zk的临时节点

 1072  ./configure --libdir=/usr/lib
1073 make
1074 make install
1075 cpan ZooKeeper
[root@wx03 c]# perldoc ZooKeeper my $zk = ZooKeeper->new(hosts => 'localhost:2181'); my $cv = AE::cv;
my @children = $zk->get_children('/', watcher => sub { my $event = shift; $cv->send($event) });
my $child_event = $cv->recv; 状态: 不稳定 知道版本1.0.0,一些 API方面的改动,最多和异常处理相关用于命令和watchers. 描述: ZooKeeper 是一个perl 接口到 Apache ZooKeeper C client library. 与Net::ZooKeeper的不同? ZooKeeper 是编写用于异步程序 支持异步程序,watchers是作为函数引用实现, 一个ZooKeeper::Dispatcher 异步调用 ZooKeeper 事件数据。 相反,Net::ZooKeeper 被用于Net::ZooKeeper::Watch classes, 用户必须交互的使用wait方法。 ZooKeeper 数据是表现为普通的perl 数据类型 ZooKeeper 事件和状态数据 是简单的hash引用和数据引用 Net::ZooKeeper 代替提供特定的perl类用于交互这个数据 ZooKeeper 利用perl异常处理; 代替 返回的C错误代码, 因为Net::ZooKeeper does, ZooKeeper 抛出一个 ZooKeeper::Error 异常对于不期望的返回代码 Data Types 数据类型: ACL 是表示一个hash引用的数组引用,每个hash引用包含一个Id,scheme,和权限。 权限标志可以从ZooKeeper::Constants package.导入 例子,ZOO_READ_ACL_UNSAFE 将表示为; [{id => 'anyone', scheme => 'world', perms => ZOO_PERM_READ}] event: 一个属性的hash引用用于一个watcher event,包含event的类型(a ZooKeeper::Constants event), 连接状态(a ZooKeeper::Constants state) 和节点触发事件的路径 {
path => '/child',
state => ZOO_CONNECTED_STATE,
type => ZOO_CHILD_EVENT,
} stat
A hashref of fields from a C Stat struct. {
aversion => 0,
ctime => 0,
cversion => 0,
czxid => 0,
ephemeralOwner => 0,
dataLength => 0,
mtime => 0,
mzxid => 0,
numChildren => 2,
pzxid => 2334,
version => 0,
} Dispatchers 调度器: ZooKeeper 使用ZooKeeper::Dispatchers 对于和用C库注册的回调通信。 那些回调 是被执行在单独的POSIX threads, 写event data 到一个 ZooKeeper::Channel ,通知 dispatcher 一个event 是准备被处理。 这个通过如何发生,perl 回调如何发生,是调度器乐行的不同 AnyEvent ZooKeeper 写Unix 管道 使用一个AnyEvent I/O watcher. T 这意味着perl 回调对于watcheres 会通过AnyEvent event loop. 执行 Interrupt 中断: ZooKeeper 使用 Async::Interrupt 回调,这意味着 perl 解释器会安全的中断(等待操作完成) 为了执行这个响应的perl回调。 查看Async::Interrupt 关于回调如何被执行。 要知道这个不会中断系统调用(比如select) 和XScode. 这意味着你的代码会被租的在select操作(比如在 AnyEvent recv), 中断的回调不会执行直到请求完成 IOAsync ZooKeeper 写一个Unix管道使用 IO::Async::Handle. IO::Async 调度器需要一个n IO::Async::Loop, 需要手动构建 my $loop = IO::Async::Loop->new;
my $disp = ZooKeeper::Dispatcher::IOAsync->new(loop => $loop);
my $zk = ZooKeeper->new(
hosts => 'localhost:2181',
dispatcher => $disp,
); ATTRIBUTES 属性: 一个逗号分隔的列表 'localhost:2181'
'zoo1.domain:2181,zoo2.domain:2181' timeout 会话超时用于ZooKeeper connection. watcher: 一个子程序引用被调用通过默认的watcher 对于ZooKeeper 会话事件, 这个属性是读写的: authentication 一个数组引用 用于ZooKeeper 认证,这个会传递一个数组到add_auth [$scheme, $credentials, %extra] buffer_length 默认的buffer 长度用于检索ZooKeeper data and paths 默认是2048 METHODS 方法: new 实现一个新的 ZooKeeper connection. my $zk = ZooKeeper->new(%args) %args
REQUIRED hosts
OPTIONAL authentication
OPTIONAL buffer_length
OPTIONAL dispatcher
OPTIONAL timeout
OPTIONAL watcher state: 得到ZooKeeper connection的状态,返回一个状态枚举 wait: 调用等待依赖 ZooKeeper::Dispatcher. 同步调用一个事件,返回 事件hash引用 watcher 被调用。 可以传递一个timeout(单位秒),会导致等待 undef 如果没有在指定时间完成 my $event = $zk->wait($seconds) OPTIONAL $seconds close: 关闭一个 ZooKeeper session. 如果 handle不是通过当前的session创建的,一个 ZOO_CLOSE_OP 不会发送给server,相反,底层的socket会关闭 reopen: 重新打开一个 ZooKeeper session 在forking后, 这个创建一个新的 ZooKeeper session, 不会关闭当前的会话 create: 创建一个新的node 使用给定的path和数据,返回 新创建的节点的path,否则抛出错误 my $created_path = $zk->create($requested_path, %extra); REQUIRED $requested_path OPTIONAL %extra
acl
buffer_length
ephemeral
sequential
value add_auth: 添加认证对于session,会自动被调用如果认证属性在构造期间被设置 一个 ZooKeeper::Error 会抛出如果请求没有成功, 决定成功或者失败认证,一个watcher 必须被传入 $zk->add_auth($scheme, $credentials, %extra) REQUIRED $scheme
REQUIRED $credentials OPTIONAL %extra
watcher delete: Delete 一个node 在给定的path,Throws a ZooKeeper::Error 如果delete删除失败 $zk->delete($path, %extra) REQUIRED $path OPTIONAL %extra
version ensure_path exists 检查是否一个节点存在于给定的path, 并可选的设置一个watcher 当节点被创建和删除, 如果成功, 返回一个节点的状态的hash引用,否则返回Undef: my $stat = $zk->exists($path, %extra) REQUIRED $path OPTIONAL %extra
watcher get_children: 得到child 节点在规定的path下, 可选的设置一个watcher 当一个child 被创建或者删除,返回一个child path名字的数组 my @child_paths = $zk->get_children($path, %extra) REQUIRED $path OPTIONAL %extra
watcher get: 设置数据在给定的path,如果成功,返回一个节点状态hashref,否则一个ZooKeeper::Error is thrown. my $stat = $zk->set($path => $value, %extra) REQUIRED $path
REQUIRED $value OPTIONAL %extra
version

ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper的更多相关文章

  1. Zookeeper基础教程(四):C#连接使用Zookeeper

    Zookeeper作为分布式的服务框架,虽然是java写的,但是强大的C#也可以连接使用. C#要连接使用Zookeeper,需要借助第三方插件,而现在主要有两个插件可供使用,分别是ZooKeeper ...

  2. Installing perl and writing your first perl program in Ubuntu

    Installing perl and writing your first perl program in Ubuntu     Installing perl and writing your f ...

  3. Perl入门(七) Perl脚本的调试

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/sunshoupo211/article/details/32711165 编程中错误不可避免.调试可 ...

  4. Linux perl: warning: Setting locale failed.perl: warning: Please check that your locale settings:

    使用 apt-get 安装软件时,总是出现下面的错误. perl: warning: Setting locale failed. perl: warning: Please check that y ...

  5. Perl入门(三)Perl的数组

    Perl数组的声明方式 Perl使用"@"符号声明一个数组:@array: 使用"()"或"qw()"声明数组中元素: 一个完整的声明方式为 ...

  6. Zookeeper基础教程(六):.net core使用Zookeeper

    Demo代码已提交到gitee,感兴趣的更有可以直接克隆使用,地址:https://gitee.com/shanfeng1000/dotnetcore-demo/tree/master/Zookeep ...

  7. Hbase 配置问题(ERROR: org.apache.hadoop.hbase.PleaseHoldException: org.apache.hadoop.hbase.PleaseHoldEx)

    ERROR: org.apache.hadoop.hbase.PleaseHoldException: org.apache.hadoop.hbase.PleaseHoldException: Mas ...

  8. 如何成为一名合格的Apache项目Committer,参与Apache开源贡献的正确姿势

    近日,孙金城老师在 "Open Source Promotion Plan - Summer 2020" 开源软件供应链点亮计划做了<如何成为一名合格的Apache项目Com ...

  9. centos LAMP第二部分apache配置 下载discuz!配置第一个虚拟主机 安装Discuz! 用户认证 配置域名跳转 配置apache的访问日志 配置静态文件缓存 配置防盗链 访问控制 apache rewrite 配置开机启动apache tcpdump 第二十节课

    centos    LAMP第二部分apache配置  下载discuz!配置第一个虚拟主机 安装Discuz! 用户认证 配置域名跳转  配置apache的访问日志  配置静态文件缓存  配置防盗链 ...

随机推荐

  1. perl5 第十三章 Perl的面向对象编程

    第十三章 Perl的面向对象编程 by flamephoenix 一.模块简介二.Perl中的类三.创建类四.构造函数 实例变量 五.方法六.方法的输出七.方法的调用八.重载九.析构函数十.继承十一. ...

  2. 基于Visual C++2013拆解世界五百强面试题--题2-输出和为一个给定整数的所有组合

    请用C语言实现 输出和为一个给定整数的所有组合 启动2012 /* 请用C语言实现 输出和为一个给定整数的所有组合 */ #include <stdio.h> //包含头文件stdio.h ...

  3. ios7毛玻璃效果实现

    首先看效果:       核心代码: //加模糊效果,image是图片,blur是模糊度 - (UIImage *)blurryImage:(UIImage *)image withBlurLevel ...

  4. H面试程序(27):字串转换

    //1 字串转换 //问题描述: //将输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:a->b,b->c,…,y->z,z->a: //若输 ...

  5. exists

    select count(*) from Table_A where exists (select count(*) from Table_B.Column1 = Table_A.Column1) 该 ...

  6. Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 2 -使用XQuery 查询XML数据

    XQuery 是一个浏览/返回XML实例的标准语言. 它比老的只能简单处理节点的XPath表达式更丰富. 你可以同XPath一样使用.或是遍历所有节点,塑造XML实例的返回等. 作为一个查询语言, 你 ...

  7. 【转】Tomcat7.0.42源代码运行环境搭建

    转自:http://tyrion.iteye.com/blog/1903608 以前看过Tomcat5的一部分源代码,当时只看了个大概的启动分析,后来看了<How Tomcat Works> ...

  8. Ubuntu 15.04 安装rmagick 2.15.4

    apt-get install  pkg-config, libmagick-dev,libmagickcore-dev, libmagickwand-dev, gem install rmagick

  9. 我常用的iphone开发学习网站[原创]

    引用地址:http://www.cnblogs.com/fuleying/archive/2011/08/13/2137032.html Google 翻译 Box2d 托德的Box2D的教程! Bo ...

  10. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家( 平衡树 )

    按鲜嫩程度排个序, 从大到小处理, 用平衡树维护价值 ---------------------------------------------------------------------- #i ...