-
Notifications
You must be signed in to change notification settings - Fork 89
Ady Liu edited this page Sep 4, 2013
·
2 revisions
ZkClient的支持设置zookeeper连接的字符串以及session失效时间和连接超时时间:
public ZkClient(String connectString, int sessionTimeout, int connectionTimeout);
例如:
IZkClient zkclient = new ZkClient('127.0.0.1:2181/xpower',2000,3000);
默认情况下超时时间为:
int DEFAULT_CONNECTION_TIMEOUT = 10000;
int DEFAULT_SESSION_TIMEOUT = 30000;
ZkClient提供一个cas机制来原子更新数据,定义如下:
void cas(String path, DataUpdater updater);
interface DataUpdater {
/**
* Updates the current data of a znode.
*
* @param currentData The current contents.
* @return the new data that should be written back to ZooKeeper.
*/
public byte[] update(byte[] currentData);
}
Zookeeper提供一个版本机制,cas操作会在更新时每次检测版本,如果失败则继续尝试直到成功更新。