/// <summary> /// For the given znode path return the stat and children list. /// /// 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. /// @since 3.3.0 /// /// @param path /// @param watcher explicit watcher /// @param stat stat of the znode designated by path /// @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, Stat stat) { 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); } if (stat != null) { DataTree.CopyStat(response.Stat, stat); } return(response.Children); }
/// <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); }
internal Packet(RequestHeader header, ReplyHeader replyHeader, IRecord request, IRecord response, byte[] data, WatchRegistration watchRegistration, string serverPath, string clientPath) { this.header = header; this.replyHeader = replyHeader; this.request = request; this.response = response; this.serverPath = serverPath; this.clientPath = clientPath; if (data != null) { this.data = data; } else { try { MemoryStream ms = new MemoryStream(); using (EndianBinaryWriter writer = new EndianBinaryWriter(EndianBitConverter.Big, ms, Encoding.UTF8)) { BinaryOutputArchive boa = BinaryOutputArchive.getArchive(writer); boa.WriteInt(-1, "len"); // We'll fill this in later if (header != null) { header.Serialize(boa, "header"); } if (request != null) { request.Serialize(boa, "request"); } ms.Position = 0; int len = Convert.ToInt32(ms.Length); // now we have the real length writer.Write(len - 4); // update the length info this.data = ms.ToArray(); } } catch (IOException e) { log.Warn("Ignoring unexpected exception", e); } } this.watchRegistration = watchRegistration; }
/// <summary> /// /// </summary> /// <param name="h"></param> /// <param name="r"></param> /// <param name="request"></param> /// <param name="response"></param> /// <param name="clientPath"></param> /// <param name="serverPath"></param> /// <param name="watchRegistration"></param> /// <param name="callback"></param> /// <param name="ctx"></param> /// <returns></returns> public Packet QueuePacket(RequestHeader h, ReplyHeader r, IRecord request, IRecord response, string clientPath, string serverPath, WatchRegistration watchRegistration, object callback, object ctx) { return(producer.QueuePacket(h, r, request, response, clientPath, serverPath, watchRegistration)); }
/// <summary> /// /// </summary> /// <param name="h"></param> /// <param name="request"></param> /// <param name="response"></param> /// <param name="watchRegistration"></param> /// <returns></returns> public ReplyHeader SubmitRequest(RequestHeader h, IRecord request, IRecord response, WatchRegistration watchRegistration) { ReplyHeader r = new ReplyHeader(); Packet p = QueuePacket(h, r, request, response, null, null, watchRegistration, null, null); if (!p.WaitUntilFinishedSlim(SessionTimeout)) { throw new TimeoutException(new StringBuilder("The request ").Append(request).Append(" timed out while waiting for a response from the server.").ToString()); } return(r); }
/// <summary> /// /// </summary> /// <param name="h"></param> /// <param name="r"></param> /// <param name="request"></param> /// <param name="response"></param> /// <param name="clientPath"></param> /// <param name="serverPath"></param> /// <param name="watchRegistration"></param> /// <returns></returns> public Packet QueuePacket(RequestHeader h, ReplyHeader r, IRecord request, IRecord response, string clientPath, string serverPath, WatchRegistration watchRegistration) { if (h.Type != (int)OpCode.Ping && h.Type != (int)OpCode.Auth) { h.Xid = Xid; } Packet p = new Packet(h, r, request, response, null, watchRegistration, clientPath, serverPath); if (!zooKeeper.State.IsAlive() || closing || Interlocked.CompareExchange(ref isDisposed, 0, 0) == 1) { if (log.IsDebugEnabled) { log.DebugFormat("Connection closing. Sending ConLossPacket. IsAlive: {0}, closing: {1}", zooKeeper.State.IsAlive(), closing); } ConLossPacket(p); } else { if (h.Type == (int)OpCode.CloseSession) { closing = true; } addPacketLast(p); } return(p); }