Exemple #1
0
        /// <summary>
        /// 递归创建该节点下的所有子节点和该节点本身。
        /// </summary>
        /// <param name="client">ZooKeeper客户端。</param>
        /// <param name="path">节点路径。</param>
        /// <param name="getNodeData">获取当前被创建节点数据的委托。</param>
        /// <param name="getNodeAcls">获取当前被创建节点权限的委托。</param>
        public static async Task CreateRecursiveAsync(this ZookeeperClient client, string path, Func <string, byte[]> getNodeData, Func <string, List <ACL> > getNodeAcls)
        {
            var data = getNodeData(path);
            var acls = getNodeAcls(path);

            try
            {
                await client.CreateAsync(path, data, acls, CreateMode.PERSISTENT);
            }
            catch (KeeperException.NodeExistsException)
            {
            }
            catch (KeeperException.NoNodeException)
            {
                var parentDir = path.Substring(0, path.LastIndexOf('/'));
                await CreateRecursiveAsync(client, parentDir, getNodeData, getNodeAcls);

                await client.CreateAsync(path, data, acls, CreateMode.PERSISTENT);
            }
        }
Exemple #2
0
 /// <summary>
 /// 创建节点。
 /// </summary>
 /// <param name="client">ZooKeeper客户端。</param>
 /// <param name="path">节点路径。</param>
 /// <param name="data">节点数据。</param>
 /// <param name="acls">权限。</param>
 /// <param name="isSequential">是否按顺序创建。</param>
 /// <returns>节点路径。</returns>
 /// <remarks>
 /// 因为使用序列方式创建节点zk会修改节点name,所以需要返回真正的节点路径。
 /// </remarks>
 public static Task <string> CreatePersistentAsync(this ZookeeperClient client, string path, byte[] data, List <ACL> acls, bool isSequential = false)
 {
     return(client.CreateAsync(path, data, acls, isSequential ? CreateMode.PERSISTENT_SEQUENTIAL : CreateMode.PERSISTENT));
 }
Exemple #3
0
 /// <summary>
 /// 创建短暂的节点。
 /// </summary>
 /// <param name="client">ZooKeeper客户端。</param>
 /// <param name="path">节点路径。</param>
 /// <param name="data">节点数据。</param>
 /// <param name="acls">权限。</param>
 /// <param name="isSequential">是否按顺序创建。</param>
 /// <returns>节点路径。</returns>
 /// <remarks>
 /// 因为使用序列方式创建节点zk会修改节点name,所以需要返回真正的节点路径。
 /// </remarks>
 public static Task <string> CreateEphemeralAsync(this ZookeeperClient client, string path, byte[] data, List <ACL> acls, bool isSequential = false)
 {
     return(client.CreateAsync(path, data, acls, isSequential ? CreateMode.EPHEMERAL_SEQUENTIAL : CreateMode.EPHEMERAL));
 }