Exemplo n.º 1
0
        public static async Task EnsurePersistentPath(this ZooKeeper client, string path)
        {
            __check_path__(path);

            if (await client.ExistAsync_(path))
            {
                return;
            }

            var sp = path.SplitZookeeperPath();
            var p  = string.Empty;

            foreach (var itm in sp)
            {
                p += $"/{itm}";
                if (!await client.ExistAsync_(p))
                {
                    await client.CreateNode_(p, CreateMode.PERSISTENT);
                }
            }
        }
Exemplo n.º 2
0
        public static async Task DeleteNodeRecursively_(this ZooKeeper client, string path)
        {
            __check_path__(path);

            var handlered_list = new List <string>();

            async Task __delete_node__(string pre_path, string p)
            {
                var pre_node = pre_path.SplitZookeeperPath();
                var cur_node = p.SplitZookeeperPath();

                if (ValidateHelper.IsEmpty(cur_node))
                {
                    throw new Exception($"不能删除:{p}");
                }

                var current_node = new List <string>().AddList_(pre_node).AddList_(cur_node).AsZookeeperPath();

                //检查死循环
                handlered_list.AddOnceOrThrow(current_node, $"递归发生错误");

                if (!await client.ExistAsync_(current_node))
                {
                    return;
                }
                var children = await client.GetNodeChildren(current_node);

                if (children.Any())
                {
                    foreach (var child in children)
                    {
                        //递归
                        await __delete_node__(current_node, child);
                    }
                }
                await client.deleteAsync(current_node);
            }

            //入口
            await __delete_node__(string.Empty, path);
        }
Exemplo n.º 3
0
        public static async Task <bool> StopWatchNode_(this ZooKeeper client, string path)
        {
            var res = await client.ExistAsync_(path);

            return(res);
        }
Exemplo n.º 4
0
        public static async Task <bool> WatchNode_(this ZooKeeper client, string path, Watcher watcher)
        {
            var res = await client.ExistAsync_(path, watcher ?? throw new ArgumentNullException(nameof(watcher)));

            return(res);
        }