internal Packet(RequestHeader header, ReplyHeader replyHeader, IRecord request, IRecord response, byte[] data, ZooKeeper.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; }
public Packet QueuePacket(RequestHeader h, ReplyHeader r, IRecord request, IRecord response, string clientPath, string serverPath, ZooKeeper.WatchRegistration watchRegistration, object callback, object ctx) { return(producer.QueuePacket(h, r, request, response, clientPath, serverPath, watchRegistration)); }
public Packet QueuePacket(RequestHeader h, ReplyHeader r, IRecord request, IRecord response, string clientPath, string serverPath, ZooKeeper.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; } // enqueue the packet when zookeeper is connected addPacketLast(p); } return(p); }
public ReplyHeader SubmitRequest(RequestHeader h, IRecord request, IRecord response, ZooKeeper.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); }