Example #1
0
        /// <summary>
        /// Set the ACL for the node of the given path if such a node exists and the
        /// given version matches the version of the node. Return the stat of the
        /// node.
        ///
        /// A KeeperException with error code KeeperException.NoNode will be thrown
        /// if no node with the given path exists.
        ///
        /// A KeeperException with error code KeeperException.BadVersion will be
        /// thrown if the given version does not match the node's version.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="acl"></param>
        /// <param name="version"></param>
        /// <returns>the stat of the node.</returns>
        public Task <Data.Stat> SetACL(string path, Data.ACL[] acl, int version)
        {
            var clientPath = path;

            Utils.PathUtils.ValidatePath(clientPath);
            var serverPath = Utils.PathUtils.PrependChroot(this._chrootPath, clientPath);

            return(this.ExecuteAsync <Data.Stat>(base.NextRequestSeqID(), Data.OpCode.SetACL,
                                                 new Data.SetACLRequest(serverPath, acl, version),
                                                 (src, response) =>
            {
                if (response.HasError())
                {
                    src.TrySetException(response.Error(clientPath));
                    return;
                }

                if (response.Payload == null || response.Payload.Length == 0)
                {
                    src.TrySetResult(null);
                    return;
                }

                Data.Stat result = null;
                try { result = Utils.Marshaller.Deserialize <Data.Stat>(response.Payload); }
                catch (Exception ex)
                {
                    src.TrySetException(ex);
                    return;
                }

                src.TrySetResult(result);
            }));
        }
Example #2
0
        /// <summary>
        /// Return the stat of the node of the given path. Return null if no such a
        /// node exists.
        ///
        /// If the watch is non-null and the call is successful (no exception is thrown),
        /// a watch will be left on the node with the given path. The watch will be
        /// triggered by a successful operation that creates/delete the node or sets
        /// the data on the node.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="watcher">The watcher.</param>
        /// <returns>the stat of the node of the given path; return null if no such a node exists.</returns>
        public Task <Data.Stat> Exists(string path, IWatcher watcher)
        {
            var clientPath = path;

            Utils.PathUtils.ValidatePath(clientPath);
            var serverPath = Utils.PathUtils.PrependChroot(this._chrootPath, clientPath);

            return(this.ExecuteAsync <Data.Stat>(base.NextRequestSeqID(), Data.OpCode.Exists,
                                                 new Data.ExistsRequest(serverPath, watcher != null),
                                                 (src, response) =>
            {
                if (response.HasError() && response.ErrorCode != Data.ZoookError.NONODE)
                {
                    src.TrySetException(response.Error(clientPath));
                    return;
                }

                if (watcher != null)    //register watcher
                {
                    if (response.HasError())
                    {
                        this._watcherManager.RegisterExistWatcher(watcher, clientPath);
                    }
                    else
                    {
                        this._watcherManager.RegisterDataWatcher(watcher, clientPath);
                    }
                }

                if (response.Payload == null || response.Payload.Length == 0)
                {
                    src.TrySetResult(null);
                    return;
                }

                Data.Stat result = null;
                try { result = Utils.Marshaller.Deserialize <Data.Stat>(response.Payload); }
                catch (Exception ex)
                {
                    src.TrySetException(ex);
                    return;
                }

                src.TrySetResult(result);
            }));
        }
 /// <summary>
 /// read
 /// </summary>
 /// <param name="formatter"></param>
 public void Read(Utils.IFormatter formatter)
 {
     this.Data = formatter.ReadBuffer();
     this.Stat = formatter.ReadRecord<Stat>();
 }
 /// <summary>
 /// read
 /// </summary>
 /// <param name="formatter"></param>
 public void Read(Utils.IFormatter formatter)
 {
     this.Children = formatter.ReadStringArray();
     this.Stat = formatter.ReadRecord<Stat>();
 }