zookeeper JavaApi 删除节点

/*
* 删除节点
* 1.删除单个节点
* 2.删除带有子节点的节点
* 3.必须成功的删除
* 4.回调
*
* */
    @Test
    public void delete1() throws Exception{
       // 1.删除单个节点
        client.delete().forPath("/app1");
    }
    @Test
    public void delete2() throws Exception{
        //2.删除带有子节点的节点
        client.delete().deletingChildrenIfNeeded().forPath("/app4");
    }
    @Test
    public void delete3() throws Exception{
        //3.必须成功的删除
        client.delete().guaranteed().forPath("/app2");
    }
    @Test
    public void delete4() throws Exception{
        //4.回调
        client.delete().guaranteed().inBackground(new BackgroundCallback() {
            @Override
            public void processResult(CuratorFramework curatorFramework, CuratorEvent curatorEvent) throws Exception {
                System.out.println("我被删除了");
                System.out.println(curatorEvent);
            }
        }).forPath("/app2");
    }
posted @ 2023-08-04 17:04  会秃头的小白  阅读(275)  评论(0编辑  收藏  举报