本文整理匯總了Java中org.I0Itec.zkclient.ZkClient.delete方法的典型用法代碼示例。如果您正苦於以下問題:Java ZkClient.delete方法的具體用法?Java ZkClient.delete怎麽用?Java ZkClient.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.I0Itec.zkclient.ZkClient
的用法示例。
在下文中一共展示了ZkClient.delete方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
private static void test() throws InterruptedException {
final ZkClient zkClient4subChild = new ZkClient("localhost:2181");
zkClient4subChild.create("/serverroot", "serverroot", Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Thread.sleep(4000);
zkClient4subChild.create("/serverroot/server1", "server1", Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Thread.sleep(4000);
zkClient4subChild.create("/serverroot/server2", "server2", Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Thread.sleep(20000);
zkClient4subChild.delete("/serverroot/server1");
zkClient4subChild.delete("/serverroot/server2");
zkClient4subChild.delete("/serverroot");
}
示例2: server
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
/**
* server端對safe接點加密
*/
private static void server() {
try {
ZkClient zc = new ZkClient("localhost:2181");
List<ACL> acls = getACL(zc);
if (zc.exists("/safe"))
zc.delete("/safe");
zc.create("/safe", "safe", acls, CreateMode.PERSISTENT);
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: test
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
/**
* @Description: zkClient主要做了兩件事情。
* @see:一件是在session loss和session expire時自動創建新的ZooKeeper實例進行重連。
* @see:一件是將一次性watcher包裝為持久watcher。
* @see:後者的具體做法是簡單的在watcher回調中,重新讀取數據的同時再注冊相同的watcher實例。
*/
private static void test() {
final ZkClient zc = new ZkClient("123.56.118.135:2181");
// 創建根節點
/* Persistent與Ephemeral 就是持久化保存到本地和不持久化的區別 ,不能再臨時節點下麵創建子節點 */
zc.createPersistent("/testroot");
// zc.createEphemeral("/testroot");
// 創建子節點
zc.create("/testroot/node1", "node1", CreateMode.EPHEMERAL);
zc.createPersistent("/testroot/node2");
zc.create("/testroot/node2/test", "node1", CreateMode.EPHEMERAL);
List<String> children = zc.getChildren("/");
log.info("根節點下麵的字節點個數" + children.size());
// 獲得子節點個數
int chidrenNumbers = zc.countChildren("/testroot");
log.info("子節點個數" + chidrenNumbers);
zc.writeData("/testroot/node2/test", "給節點寫數據");
// 刪除節點
zc.delete("/testroot/node2/test");
zc.delete("/testroot/node2");
zc.delete("/testroot/node1");
zc.delete("/testroot");
}
示例4: test
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
@Test
public void test() throws Exception {
ZkClient zkClient = new ZkClient("127.0.0.1:2181", 5000, 5000);
zkClient.delete("/adfasdf/adfasdf");
System.out.println("deleted~~~~~~~~");
Thread.sleep(10000L);
zkClient.close();
}
示例5: 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);
}
}
示例6: clear
import org.I0Itec.zkclient.ZkClient; //導入方法依賴的package包/類
@Override
public void clear() {
ZkClient client = client();
try { client.delete(path); }
finally { client.close(); }
}