本文整理汇总了Java中org.I0Itec.zkclient.ZkClient.createEphemeral方法的典型用法代码示例。如果您正苦于以下问题:Java ZkClient.createEphemeral方法的具体用法?Java ZkClient.createEphemeral怎么用?Java ZkClient.createEphemeral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.I0Itec.zkclient.ZkClient
的用法示例。
在下文中一共展示了ZkClient.createEphemeral方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public ZkClient create(){
ZkClient zkClient=new ZkClient(ZKClientConfiguration.address);
zkClient.subscribeChildChanges("/temp", new IZkChildListener() {
@Override
public void handleChildChange(String s, List<String> list) throws Exception {
System.out.println(s);
System.out.println(list);
}
});
zkClient.createEphemeral("/temp");
return zkClient;
}
示例2: register
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
/**
* 向注册中心进行注册,生成该服务的编号并返回
* @param registerDto
* @return
*/
@Override
public String register(RegisterDto registerDto) {
String host = registerDto.getHost();
String app = registerDto.getApp();
// 向注册中心注册
ZkClient zkClient = registerDto.getZkClient();
zkClient.createPersistent(Constants.ZK_REGISTRY_SERVICE_ROOT_PATH + Constants.SLASH + app, true);
IdGen idGen = new IncrementIdGen(registerDto);
String id = idGen.nextId();
zkClient.createEphemeral(Constants.ZK_REGISTRY_SERVICE_ROOT_PATH + Constants.SLASH + app + Constants.SLASH + host, id);
return id;
}
示例3: createNode
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public void createNode() {
ZkClient zkClient = new ZkClient(Config.ZK_SERVER_CLUSTER, Config.DEFUALT_TIME_OUT);
zkClient.createEphemeral(Config.DEFAULT_TEST_PATH, Config.DEFAULT_NODE_DATA);
}
示例4: start
import org.I0Itec.zkclient.ZkClient; //导入方法依赖的package包/类
public synchronized void start() {
if (started) {
return;
}
try {
String ip = AppInfo.get("soa.host", AppInfo.getIp());
path = ZKConst.SOA_ROOT + "/" + AppInfo.get("soa.zk.host", ip) + ":"
+ AppInfo.get("soa.zk.port", String.valueOf(port));
zkUrl = AppInfo.getZKUrl();
ZkClient client = ZkClientHolder.getZkClient(zkUrl);
ZkClientHolder.makeSure(client, ZKConst.SOA_ROOT);
startServer(ip, port);
client.delete(path);
IZkStateListener stateListener = new IZkStateListener() {
@Override
public void handleStateChanged(KeeperState state) throws Exception {
Log.get("sumk.rpc").info("zk state changed:{}", state);
}
@Override
public void handleNewSession() throws Exception {
client.createEphemeral(path, createZkRouteData());
}
@Override
public void handleSessionEstablishmentError(Throwable error) throws Exception {
Log.get("sumk.rpc").error("SessionEstablishmentError#" + error.getMessage(), error);
}
};
client.createEphemeral(path, createZkRouteData());
client.subscribeStateChanges(stateListener);
started = true;
} catch (Exception e) {
Log.printStack(e);
System.exit(-1);
}
}