ZooKeeper - Perl bindings for Apache ZooKeeper Perl绑定用于 Apache ZooKeeper
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的更多相关文章
- Zookeeper基础教程(四):C#连接使用Zookeeper
Zookeeper作为分布式的服务框架,虽然是java写的,但是强大的C#也可以连接使用. C#要连接使用Zookeeper,需要借助第三方插件,而现在主要有两个插件可供使用,分别是ZooKeeper ...
- 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 ...
- Perl入门(七) Perl脚本的调试
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/sunshoupo211/article/details/32711165 编程中错误不可避免.调试可 ...
- 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 ...
- Perl入门(三)Perl的数组
Perl数组的声明方式 Perl使用"@"符号声明一个数组:@array: 使用"()"或"qw()"声明数组中元素: 一个完整的声明方式为 ...
- Zookeeper基础教程(六):.net core使用Zookeeper
Demo代码已提交到gitee,感兴趣的更有可以直接克隆使用,地址:https://gitee.com/shanfeng1000/dotnetcore-demo/tree/master/Zookeep ...
- Hbase 配置问题(ERROR: org.apache.hadoop.hbase.PleaseHoldException: org.apache.hadoop.hbase.PleaseHoldEx)
ERROR: org.apache.hadoop.hbase.PleaseHoldException: org.apache.hadoop.hbase.PleaseHoldException: Mas ...
- 如何成为一名合格的Apache项目Committer,参与Apache开源贡献的正确姿势
近日,孙金城老师在 "Open Source Promotion Plan - Summer 2020" 开源软件供应链点亮计划做了<如何成为一名合格的Apache项目Com ...
- centos LAMP第二部分apache配置 下载discuz!配置第一个虚拟主机 安装Discuz! 用户认证 配置域名跳转 配置apache的访问日志 配置静态文件缓存 配置防盗链 访问控制 apache rewrite 配置开机启动apache tcpdump 第二十节课
centos LAMP第二部分apache配置 下载discuz!配置第一个虚拟主机 安装Discuz! 用户认证 配置域名跳转 配置apache的访问日志 配置静态文件缓存 配置防盗链 ...
随机推荐
- C语言参数传递
//--------------------单向值传递------------------------ // swap这个方法在被调用时,给形参a,b分配了空间 // 主调函数将[数值]传递给[形参] ...
- 给定一个字符串里面只有"R" "G" "B" 三个字符,请排序,最终结果的顺序是R在前 G中 B在后。 要求:空间复杂度是O(1),且只能遍历一次字符串。
题目:给定一个字符串里面只有"R" "G" "B" 三个字符,请排序,最终结果的顺序是R在前 G中 B在后. 要求:空间复杂度是O(1),且 ...
- Why is celsius = 5 * (fahr - 32) / 9 ?
Go to my personal blog There is a program to print Fahrenheit-Celsius table as below. #include <s ...
- SVN同步出现故障
1.错误描写叙述 同步SVNStatusSubscribe时报告了错误,1中的0个资源已经同步 同步/frame时错误发生:Error getting status for resourc ...
- 在TextBox里面仅仅允许数字,按Enter键进入下一个TextBox
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> ...
- React Native-目前最火的前端技术?
做为一名产品经理,你是否遇到过这样的窘境,“帮我把字体调成 16号呗,颜色变成 #FFFF00FF,老大说这里最好改一下”,作为一名 app 的开发只能无奈但心里窃喜的告诉你,“只能等下个版本了,必须 ...
- 【转】 利用spring的profile切换不同的环境
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- php怎样求一个数组中最长的
<?php $arr = array( 0 => 'd', 1 => '68b3', 2 => 'a86', 3 => 'c9aa97b23b71d5c', 4 => ...
- HDU1004题解分析(字符串处理)
这道题是从上个星期开始做的,看到题时觉得似曾相似,好像做过,理了一下思路敲完代码又不对,后来发现是数组用错了,之后又重新想了数组和比较用法,昨天改了一个多小时,后来样例输出全部正确,所有情况都考虑到了 ...
- memcache学习使用
一.安装 二.telnet测试 启动:memcached -d -m 120.24.242.100 -p 11211 -u root 测试:telnet localhost 11211 >> ...