public int CompareTo(object obj) { WatcherEvent peer = (WatcherEvent)obj; if (peer == null) { throw new InvalidOperationException("Comparing different types of records."); } int ret = 0; ret = (Type == peer.Type) ? 0 : ((Type < peer.Type) ? -1 : 1); if (ret != 0) { return(ret); } ret = (State == peer.State) ? 0 : ((State < peer.State) ? -1 : 1); if (ret != 0) { return(ret); } ret = Path.CompareTo(peer.Path); if (ret != 0) { return(ret); } return(ret); }
public override bool Equals(object obj) { WatcherEvent peer = (WatcherEvent)obj; if (peer == null) { return(false); } if (Object.ReferenceEquals(peer, this)) { return(true); } bool ret = false; ret = (Type == peer.Type); if (!ret) { return(ret); } ret = (State == peer.State); if (!ret) { return(ret); } ret = Path.Equals(peer.Path); if (!ret) { return(ret); } return(ret); }
public int CompareTo(object obj) { WatcherEvent watcherEvent = (WatcherEvent)obj; if (watcherEvent == null) { throw new InvalidOperationException("Comparing different types of records."); } int num1 = this.Type == watcherEvent.Type ? 0 : (this.Type < watcherEvent.Type ? -1 : 1); if (num1 != 0) { return(num1); } int num2 = this.State == watcherEvent.State ? 0 : (this.State < watcherEvent.State ? -1 : 1); if (num2 != 0) { return(num2); } int num3 = this.Path.CompareTo(watcherEvent.Path); if (num3 != 0) { return(num3); } return(num3); }
public override bool Equals(object obj) { WatcherEvent watcherEvent = (WatcherEvent)obj; if (watcherEvent == null) { return(false); } if (object.ReferenceEquals((object)watcherEvent, (object)this)) { return(true); } bool flag1 = this.Type == watcherEvent.Type; if (!flag1) { return(flag1); } bool flag2 = this.State == watcherEvent.State; if (!flag2) { return(flag2); } bool flag3 = this.Path.Equals(watcherEvent.Path); if (!flag3) { return(flag3); } return(flag3); }
public override bool Equals(object obj) { WatcherEvent objA = (WatcherEvent)obj; if (objA == null) { return(false); } if (object.ReferenceEquals(objA, this)) { return(true); } bool flag = false; flag = this.Type == objA.Type; if (flag) { flag = this.State == objA.State; if (!flag) { return(flag); } flag = this.Path.Equals(objA.Path); if (!flag) { return(flag); } } return(flag); }
public int CompareTo(object obj) { WatcherEvent event2 = (WatcherEvent)obj; if (event2 == null) { throw new InvalidOperationException("Comparing different types of records."); } int num = 0; num = (this.Type == event2.Type) ? 0 : ((this.Type < event2.Type) ? -1 : 1); if (num == 0) { num = (this.State == event2.State) ? 0 : ((this.State < event2.State) ? -1 : 1); if (num != 0) { return(num); } num = this.Path.CompareTo(event2.Path); if (num != 0) { return(num); } } return(num); }
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 WatchedEvent(WatcherEvent eventMessage) { state = (KeeperState)Enum.ToObject(typeof(KeeperState), eventMessage.State); type = (EventType)Enum.ToObject(typeof (EventType), eventMessage.Type); path = eventMessage.Path; }
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()); } } }