Exemplo n.º 1
0
        /// <summary>
        /// Return the list of the children of the node of the given path.
        ///
        /// 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 willbe
        /// triggered by a successful operation that deletes the node of the given
        /// path or creates/delete a child under the node.
        ///
        /// The list of children returned is not sorted and no guarantee is provided
        /// as to its natural or lexical order.
        ///
        /// A KeeperException with error code KeeperException.NoNode will be thrown
        /// if no node with the given path exists.
        /// @param path
        /// @param watcher explicit watcher
        /// @return an unordered array of children of the node with the given path
        /// @throws InterruptedException If the server transaction is interrupted.
        /// @throws KeeperException If the server signals an error with a non-zero error code.
        /// @throws IllegalArgumentException if an invalid path is specified
        /// </summary>
        public IEnumerable <string> GetChildren(string path, IWatcher watcher)
        {
            string clientPath = path;

            PathUtils.ValidatePath(clientPath);

            // the watch contains the un-chroot path
            WatchRegistration wcb = null;

            if (watcher != null)
            {
                wcb = new ChildWatchRegistration(watchManager, watcher, clientPath);
            }

            string serverPath = PrependChroot(clientPath);

            RequestHeader h = new RequestHeader();

            h.Type = (int)OpCode.GetChildren2;
            GetChildren2Request  request  = new GetChildren2Request(serverPath, watcher != null);
            GetChildren2Response response = new GetChildren2Response();
            ReplyHeader          r        = cnxn.SubmitRequest(h, request, response, wcb);

            if (r.Err != 0)
            {
                throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath);
            }
            return(response.Children);
        }
Exemplo n.º 2
0
        //added by Yang Li at Feb.29th, 2016
        public byte[] GetRemark(string path, IWatcher watcher, Stat stat)
        {
            string clientPath = path;

            PathUtils.ValidatePath(clientPath);

            // the watch contains the un-chroot path
            WatchRegistration wcb = null;

            if (watcher != null)
            {
                wcb = new DataWatchRegistration(watchManager, watcher, clientPath);
            }

            string serverPath = PrependChroot(clientPath);

            RequestHeader h = new RequestHeader();

#warning code here
            //h.Type = (int)OpCode.GetRemark;
            h.Type = (int)OpCode.GetData;
            GetRemarkRequest  request  = new GetRemarkRequest(serverPath, watcher != null);
            GetRemarkResponse response = new GetRemarkResponse();
            ReplyHeader       r        = cnxn.SubmitRequest(h, request, response, wcb);
            if (r.Err != 0)
            {
                throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath);
            }
            if (stat != null)
            {
                DataTree.CopyStat(response.Stat, stat);
            }
            return(response.Remark);
        }
Exemplo n.º 3
0
        private async Task <IEnumerable <string> > GetChildrenAsyncInternal(string path, IWatcher watcher, Stat stat, bool sync)
        {
            string clientPath = path;

            PathUtils.ValidatePath(clientPath);

            // the watch contains the un-chroot path
            WatchRegistration wcb = null;

            if (watcher != null)
            {
                wcb = new ChildWatchRegistration(watchManager, watcher, clientPath);
            }

            string serverPath = PrependChroot(clientPath);

            RequestHeader h = new RequestHeader();

            h.Type = (int)OpCode.GetChildren2;
            GetChildren2Request  request  = new GetChildren2Request(serverPath, watcher != null);
            GetChildren2Response response = new GetChildren2Response();
            ReplyHeader          r        = sync ? cnxn.SubmitRequest(h, request, response, wcb)
                : await cnxn.SubmitRequestAsync(h, request, response, wcb).ConfigureAwait(false);

            if (r.Err != 0)
            {
                throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath);
            }
            if (stat != null)
            {
                DataTree.CopyStat(response.Stat, stat);
            }
            return(response.Children);
        }
Exemplo n.º 4
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 Stat Exists(string path, IWatcher watcher)
        {
            string clientPath = path;

            PathUtils.ValidatePath(clientPath);

            // the watch contains the un-chroot path
            WatchRegistration wcb = null;

            if (watcher != null)
            {
                wcb = new ExistsWatchRegistration(watchManager, watcher, clientPath);
            }

            string serverPath = PrependChroot(clientPath);

            RequestHeader h = new RequestHeader();

            h.Type = (int)OpCode.Exists;
            ExistsRequest   request  = new ExistsRequest(serverPath, watcher != null);
            SetDataResponse response = new SetDataResponse();
            ReplyHeader     r        = cnxn.SubmitRequest(h, request, response, wcb);

            if (r.Err != 0)
            {
                if (r.Err == (int)KeeperException.Code.NONODE)
                {
                    return(null);
                }
                throw KeeperException.Create((KeeperException.Code)Enum.ToObject(typeof(KeeperException.Code), r.Err), clientPath);
            }

            return(response.Stat.Czxid == -1 ? null : response.Stat);
        }
Exemplo n.º 5
0
 internal ReplyHeader submitRequest(RequestHeader h, Record request, Record response,
                                    WatchRegistration watchRegistration)
 {
     return(cnxn.submitRequest(h, request, response, watchRegistration).GetAwaiter().GetResult());
 }