本文整理匯總了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);
}
}