一. 创建会话
Zookeeper(String connectString, int sessionTimeout, Watcher watcher);
Zookeeper(String connectString, int sessionTimeout, Watcher watcher, boolean canBeReadOnly);
Zookeeper(String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd);
Zookeeper(String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd, boolean canBeReadOnly);
connectString:服务器列表;
sessionTimeout:会话超时时间;
watcher:事件通知处理器;
canBeReadOnly:当一个机器和集群中过半及以上失去网络连接时,是否还能提供读服务;
sessionId,sessionPasswd:会话ID和秘钥,能够确定一个唯一的会话,客户端可以用来实现会话复用;
二. 创建节点
String create(final String path, byte data[], List<ACL> acl, CreateMode createMode);
String create(final String path, byte data[], List<ACL> acl, CreateMode createMode, StringCallback cb, Object ctx);
path:节点路径;
data[]:节点创建后的初始内容;
acl:节点的ACL策略;
createMode:节点类型;
cb:异步回调函数;
ctx:用于传递一个对象,可以在回调方法执行时使用,通常放一个上下文信息;
三. 删除节点
public void delete(final String path, int version);
public void delete(final String path, int version, VoidCallback cb, Object ctx);
version:要删除的节点的数据版本;
四. 读取数据
用来获取一个节点的所有子节点:
List<String> getChildren(final String path, Watcher watcher);
List<String> getChildren(String path, boolean watch);
void getChildren(final String path, Watcher watcher, ChildrenCallback cb, Object ctx);
void getChildren(String path, boolean watch, ChildrenCallback cb, Object ctx);
List<String> getChildren(final String path, Watcher watcher, Stat stat);
List<String> getChildren(String path, boolean watch, Stat stat);
用来获取一个节点的数据内容:
byte[] getData(final String path, Watcher watcher, Stat stat);
byte[] getData(String path, boolean watch, Stat stat);
void getData(final String path, Watcher watcher, DataCallback cb, Object ctx);
void getData(String path, boolean watch, DataCallback cb, Object ctx);
watch:是否需要注册一个Watcher;
stat:节点的状态信息;
五. 更新数据
Stat setData(final String path, byte data[], int version);
void setData(final String path, byte data[], int version, StatCallback cb, Object ctx);
data[]:使用该数据的内容覆盖现有数据内容;
六. 检测节点是否存在
public Stat exists(final String path, Watcher watcher);
public Stat exists(String path, boolean watch);
public void exists(final String path, Watcher watcher, StatCallback cb, Object ctx);
public void exists(String path, boolean watch, StatCallback cb, Object ctx);
七. 权限控制
addAuthInfo(String scheme, byte[] auth);
scheme:权限控制模式,分为world,auth,digest,ip和super;
auth:具体的权限信息;
浙公网安备 33010602011771号