zookeeper-API操作-刪除節點
阿新 • • 發佈:2021-07-14
工程具體結構見上文
https://www.cnblogs.com/aoligei/p/15010287.html
//=============================delete============================== /** * 1.刪除單個節點 client.delete().forPath("/test1"); * 2.刪除帶有子節點的節點 client.delete().deletingChildrenIfNeeded().forPath("/test4"); * 3.必須成功的刪除 (防止網路抖動,重試刪除) client.delete().guaranteed().forPath("/test2"); * 4.回撥 client.delete().guaranteed().inBackground(new BackgroundCallback() { * public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {*/ @Test public void testDelete1() throws Exception { //1.刪除單個節點 client.delete().forPath("/test1"); } @Test public void testDelete2() throws Exception { //2.刪除帶有子節點的節點 client.delete().deletingChildrenIfNeeded().forPath("/test4"); } @Test publicvoid testDelete3() throws Exception { //3.必須成功的刪除 (網路延遲,沒連線上服務端) client.delete().guaranteed().forPath("/test2"); } @Test public void testDelete4() throws Exception { //4.回撥 client.delete().guaranteed().inBackground(new BackgroundCallback() { publicvoid processResult(CuratorFramework client, CuratorEvent event) throws Exception { System.out.println("執行刪除操作"); System.out.println(event); } }).forPath("/test"); }
1、刪除節點
2、刪除帶有子節點的節點
刪除操作後
3、必須成功的刪除 (可能網路原因造成刪除失敗)
4、回撥 (節點刪完了就自己建立)