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的访问日志 配置静态文件缓存 配置防盗链 ...
随机推荐
- 别忘记给你博客的windows live writer配置 ping服务
写好一篇博客,想要实现秒收.就必须要为文章添加ping服务. 这里介绍一下给wlw添加ping服务的办法. 点击工具---选项--ping服务器. 在右侧栏中加入以下地址 http://rpc.pin ...
- BZOJ 1005 明明的烦恼 (组合数学)
题解:n为树的节点数,d[ ]为各节点的度数,m为无限制度数的节点数. 则 所以要求在n-2大小的数组中插入tot各序号,共有种插法: 在tot各序号排列中,插第一个节点的 ...
- HDU 1848 Fibonacci again and again
题解:尼姆博弈,对于1至1000计算SG函数,每次取最小的前继值,SG值异或为0则为P-position. #include <cstdio> #include <cstring&g ...
- android AChartEngine源代码
昨天翻自己曾经下过的apache开源project项目,看到一个AChartEnginee看了一下自带的Demo才意识到这个东西的强大.立刻想把源代码down一份,在CSDN上有人挂5分让人下载,实在 ...
- MySQL几种方法的数据库备份
MySQL有几个方法来备份 最近博客一直想写点.可是不知道写什么,感觉自己近期的知识没有什么添加,今天想到了一篇能够写的博客.曾经试过依据data目录备份MySQL.可是从来没有成功过.前几天帮助朋友 ...
- 什么是DNS劫持和DNS污染?
什么是DNS劫持和DNS污染? http://blogread.cn/it/article/7758?f=weekly 说明 我们知道,某些网络运营商为了某些目的,对 DNS 进行了某些操作,导致使用 ...
- openstack第1天
入门openstack题外篇 老实说,我在写这篇文章的时候,对云的了解还是比较模糊的,也许是刚接触,不管怎样 总得写点什么,写完之后也许数月之后,感觉写的不是那么好,到时候在做修该吧! 今天我们就提一 ...
- Qualified name lookup
Qualified name lookup Qualified name lookup Enumerations Class members Namespace members Unqualified ...
- FFTW程序Demo
#include<stdio.h> #include<stdlib.h> #include <fftw3.h> #include<string.h> # ...
- BZOJ 1898: [Zjoi2004]Swamp 沼泽鳄鱼( dp + 矩阵快速幂 )
----------------------------------------------------------------------- #include<cstdio> #incl ...