Esempio n. 1
0
        public override bool Equals(object obj)
        {
            ReplyHeader objA = (ReplyHeader)obj;

            if (objA == null)
            {
                return(false);
            }
            if (object.ReferenceEquals(objA, this))
            {
                return(true);
            }
            bool flag = false;

            flag = this.Xid == objA.Xid;
            if (flag)
            {
                flag = this.Zxid == objA.Zxid;
                if (!flag)
                {
                    return(flag);
                }
                flag = this.Err == objA.Err;
                if (!flag)
                {
                    return(flag);
                }
            }
            return(flag);
        }
Esempio n. 2
0
        public int CompareTo(object obj)
        {
            ReplyHeader replyHeader = (ReplyHeader)obj;

            if (replyHeader == null)
            {
                throw new InvalidOperationException("Comparing different types of records.");
            }
            int num1 = this.Xid == replyHeader.Xid ? 0 : (this.Xid < replyHeader.Xid ? -1 : 1);

            if (num1 != 0)
            {
                return(num1);
            }
            int num2 = this.Zxid == replyHeader.Zxid ? 0 : (this.Zxid < replyHeader.Zxid ? -1 : 1);

            if (num2 != 0)
            {
                return(num2);
            }
            int num3 = this.Err == replyHeader.Err ? 0 : (this.Err < replyHeader.Err ? -1 : 1);

            if (num3 != 0)
            {
                return(num3);
            }
            return(num3);
        }
Esempio n. 3
0
        public int CompareTo(object obj)
        {
            ReplyHeader header = (ReplyHeader)obj;

            if (header == null)
            {
                throw new InvalidOperationException("Comparing different types of records.");
            }
            int num = 0;

            num = (this.Xid == header.Xid) ? 0 : ((this.Xid < header.Xid) ? -1 : 1);
            if (num == 0)
            {
                num = (this.Zxid == header.Zxid) ? 0 : ((this.Zxid < header.Zxid) ? -1 : 1);
                if (num != 0)
                {
                    return(num);
                }
                num = (this.Err == header.Err) ? 0 : ((this.Err < header.Err) ? -1 : 1);
                if (num != 0)
                {
                    return(num);
                }
            }
            return(num);
        }
Esempio n. 4
0
        public override bool Equals(object obj)
        {
            ReplyHeader peer = (ReplyHeader)obj;

            if (peer == null)
            {
                return(false);
            }
            if (Object.ReferenceEquals(peer, this))
            {
                return(true);
            }
            bool ret = false;

            ret = (Xid == peer.Xid);
            if (!ret)
            {
                return(ret);
            }
            ret = (Zxid == peer.Zxid);
            if (!ret)
            {
                return(ret);
            }
            ret = (Err == peer.Err);
            if (!ret)
            {
                return(ret);
            }
            return(ret);
        }
Esempio n. 5
0
        public override bool Equals(object obj)
        {
            ReplyHeader replyHeader = (ReplyHeader)obj;

            if (replyHeader == null)
            {
                return(false);
            }
            if (object.ReferenceEquals((object)replyHeader, (object)this))
            {
                return(true);
            }
            bool flag1 = this.Xid == replyHeader.Xid;

            if (!flag1)
            {
                return(flag1);
            }
            bool flag2 = this.Zxid == replyHeader.Zxid;

            if (!flag2)
            {
                return(flag2);
            }
            bool flag3 = this.Err == replyHeader.Err;

            if (!flag3)
            {
                return(flag3);
            }
            return(flag3);
        }
Esempio n. 6
0
        public int CompareTo(object obj)
        {
            ReplyHeader peer = (ReplyHeader)obj;

            if (peer == null)
            {
                throw new InvalidOperationException("Comparing different types of records.");
            }
            int ret = 0;

            ret = (Xid == peer.Xid)? 0 :((Xid < peer.Xid)?-1:1);
            if (ret != 0)
            {
                return(ret);
            }
            ret = (Zxid == peer.Zxid)? 0 :((Zxid < peer.Zxid)?-1:1);
            if (ret != 0)
            {
                return(ret);
            }
            ret = (Err == peer.Err)? 0 :((Err < peer.Err)?-1:1);
            if (ret != 0)
            {
                return(ret);
            }
            return(ret);
        }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
 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;
 }
        public Packet QueuePacket(RequestHeader h, ReplyHeader r, IRecord request, IRecord response, string clientPath, string serverPath, ZooKeeper.WatchRegistration watchRegistration)
        {
            lock (outgoingQueueLock)
            {
                //lock here for XID?
                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);
                p.clientPath = clientPath;
                p.serverPath = serverPath;

                if (!zooKeeper.State.IsAlive())
                    ConLossPacket(p);
                else
                {
                    outgoingQueue.AddLast(p);
                    Monitor.PulseAll(outgoingQueueLock);
                }

                return p;
            }
        }
        private void ReadResponse()
        {
            using (MemoryStream ms = new MemoryStream(incomingBuffer))
            using (var reader = new EndianBinaryReader(EndianBitConverter.Big, ms, Encoding.UTF8))
            {
                BinaryInputArchive bbia = BinaryInputArchive.GetArchive(reader);
                ReplyHeader replyHdr = new ReplyHeader();

                replyHdr.Deserialize(bbia, "header");
                if (replyHdr.Xid == -2)
                {
                    // -2 is the xid for pings
                    if (PingLog.IsDebugEnabled)
                    {
                        PingLog.Debug(string.Format("Got ping response for sessionid: 0x{0:X} after {1}ms", conn.SessionId, (DateTime.Now.Nanos() - lastPingSentNs) / 1000000));
                    }
                    return;
                }
                if (replyHdr.Xid == -4)
                {
                    // -4 is the xid for AuthPacket
                    // TODO: process AuthPacket here
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Got auth sessionid:0x{0:X}", conn.SessionId));
                    }
                    return;
                }
                if (replyHdr.Xid == -1)
                {
                    // -1 means notification
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Got notification sessionid:0x{0}", conn.SessionId));
                    }
                    WatcherEvent @event = new WatcherEvent();
                    @event.Deserialize(bbia, "response");

                    // convert from a server path to a client path
                    if (conn.ChrootPath != null)
                    {
                        string serverPath = @event.Path;
                        if (serverPath.CompareTo(conn.ChrootPath) == 0)
                            @event.Path = "/";
                        else
                            @event.Path = serverPath.Substring(conn.ChrootPath.Length);
                    }

                    WatchedEvent we = new WatchedEvent(@event);
                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Got {0} for sessionid 0x{1:X}", we, conn.SessionId));
                    }

                    conn.consumer.QueueEvent(we);
                    return;
                }
                if (pendingQueue.IsEmpty())
                {
                    throw new IOException(string.Format("Nothing in the queue, but got {0}", replyHdr.Xid));
                }

                Packet packet;
                lock (pendingQueueLock)
                {
                    packet = pendingQueue.First.Value;
                    pendingQueue.RemoveFirst();
                }
                /*
             * Since requests are processed in order, we better get a response
             * to the first request!
             */
                try
                {
                    if (packet.header.Xid != replyHdr.Xid)
                    {
                        packet.replyHeader.Err = (int)KeeperException.Code.CONNECTIONLOSS;
                        throw new IOException(string.Format("Xid out of order. Got {0} expected {1}", replyHdr.Xid, packet.header.Xid));
                    }

                    packet.replyHeader.Xid = replyHdr.Xid;
                    packet.replyHeader.Err = replyHdr.Err;
                    packet.replyHeader.Zxid = replyHdr.Zxid;
                    if (replyHdr.Zxid > 0)
                    {
                        lastZxid = replyHdr.Zxid;
                    }
                    if (packet.response != null && replyHdr.Err == 0)
                    {
                        packet.response.Deserialize(bbia, "response");
                    }

                    if (LOG.IsDebugEnabled)
                    {
                        LOG.Debug(string.Format("Reading reply sessionid:0x{0:X}, packet:: {1}", conn.SessionId, packet));
                    }
                }
                finally
                {
                    FinishPacket(packet);
                }
            }
        }
        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;
        }
        private void ReadResponse(byte[] content)
        {
            using (var reader = new EndianBinaryReader(EndianBitConverter.Big, new MemoryStream(content), Encoding.UTF8))
            {
                BinaryInputArchive bbia = BinaryInputArchive.GetArchive(reader);
                ReplyHeader replyHdr = new ReplyHeader();

                replyHdr.Deserialize(bbia, "header");
                if (replyHdr.Xid == -2)
                {
                    // -2 is the xid for pings
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got ping response for sessionid: 0x{0:X} after {1}ms", conn.SessionId, (DateTime.UtcNow.Nanos() - lastPingSentNs) / 1000000);
                    return;
                }
                if (replyHdr.Xid == -4)
                {
                    // -2 is the xid for AuthPacket
                    // TODO: process AuthPacket here
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got auth sessionid:0x{0:X}", conn.SessionId);
                    return;
                }
                if (replyHdr.Xid == -1)
                {
                    // -1 means notification
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got notification sessionid:0x{0}", conn.SessionId);

                    WatcherEvent @event = new WatcherEvent();
                    @event.Deserialize(bbia, "response");

                    // convert from a server path to a client path
                    if (conn.ChrootPath != null)
                    {
                        string serverPath = @event.Path;
                        if (serverPath.CompareTo(conn.ChrootPath) == 0)
                            @event.Path = PathUtils.PathSeparator;
                        else
                            @event.Path = serverPath.Substring(conn.ChrootPath.Length);
                    }

                    WatchedEvent we = new WatchedEvent(@event);
                    if (LOG.IsDebugEnabled)
                        LOG.DebugFormat("Got {0} for sessionid 0x{1:X}", we, conn.SessionId);

                    conn.consumer.QueueEvent(we);
                    return;
                }
                Packet packet;
                /*
             * Since requests are processed in order, we better get a response
             * to the first request!
             */
                if (pendingQueue.TryDequeue(out packet))
                {
                    try
                    {
                        if (packet.header.Xid != replyHdr.Xid)
                        {
                            packet.replyHeader.Err = (int)KeeperException.Code.CONNECTIONLOSS;
                            throw new IOException(new StringBuilder("Xid out of order. Got ").Append(replyHdr.Xid).Append(" expected ").Append(packet.header.Xid).ToString());
                        }

                        packet.replyHeader.Xid = replyHdr.Xid;
                        packet.replyHeader.Err = replyHdr.Err;
                        packet.replyHeader.Zxid = replyHdr.Zxid;
                        if (replyHdr.Zxid > 0)
                            lastZxid = replyHdr.Zxid;

                        if (packet.response != null && replyHdr.Err == 0)
                            packet.response.Deserialize(bbia, "response");

                        if (LOG.IsDebugEnabled)
                            LOG.DebugFormat("Reading reply sessionid:0x{0:X}, packet:: {1}", conn.SessionId, packet);
                    }
                    finally
                    {
                        FinishPacket(packet);
                    }
                }
                else
                {
                    throw new IOException(new StringBuilder("Nothing in the queue, but got ").Append(replyHdr.Xid).ToString());
                }
            }
        }        
Esempio n. 14
0
 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);
     lock (p)
     {
         while (!p.Finished)
         {
             if (!Monitor.Wait(p, SessionTimeout))
                 throw new TimeoutException(string.Format("The request {0} timed out while waiting for a resposne from the server.", request));
         }
     }
     return r;
 }