Пример #1
0
 public override Task process(WatchedEvent @event)
 {
     lock (this) {
         if (@event.getState() == Event.KeeperState.SyncConnected ||
             @event.getState() == Event.KeeperState.ConnectedReadOnly)
         {
             Monitor.PulseAll(this);
             clientConnected.Set();
         }
         else
         {
             Monitor.PulseAll(this);
         }
     }
     return(CompletedTask);
 }
Пример #2
0
        private void queueEvent(WatchedEvent @event)
        {
            if (@event.get_Type() == Watcher.Event.EventType.None &&
                sessionState.Value == @event.getState())
            {
                return;
            }
            sessionState.Value = @event.getState();
            // materialize the watchers based on the event
            WatcherSetEventPair pair = new WatcherSetEventPair(
                watcher.materialize(@event.getState(), @event.get_Type(),
                                    @event.getPath()), @event);

            // queue the pair (watch set & event) for later processing
            waitingEvents.Enqueue(pair);
            waitingEventsSignal.Set();
        }
Пример #3
0
 public override Task process(WatchedEvent @event)
 {
     return(CompletedTask);
     // nada
 }
Пример #4
0
        internal void readResponse(ByteBuffer incomingBuffer)
        {
            BigEndianBinaryReader bbis = new BigEndianBinaryReader(incomingBuffer.Stream);
            BinaryInputArchive    bbia = BinaryInputArchive.getArchive(bbis);

            ReplyHeader replyHdr = new ReplyHeader();

            ((Record)replyHdr).deserialize(bbia, "header");
            if (replyHdr.getXid() == -2)
            {
                // -2 is the xid for pings
                if (LOG.isDebugEnabled())
                {
                    LOG.debug("Got ping response for sessionid: 0x" + sessionId.ToHexString() + " after " +
                              ((TimeHelper.ElapsedNanoseconds - lastPingSentNs) / 1000000) + "ms");
                }
                return;
            }
            if (replyHdr.getXid() == -4)
            {
                // -4 is the xid for AuthPacket
                if (replyHdr.getErr() == (int)KeeperException.Code.AUTHFAILED)
                {
                    state.Value = ZooKeeper.States.AUTH_FAILED;
                    queueEvent(new WatchedEvent(Watcher.Event.EventType.None,
                                                Watcher.Event.KeeperState.AuthFailed, null));
                }
                if (LOG.isDebugEnabled())
                {
                    LOG.debug("Got auth sessionid:0x"
                              + sessionId.ToHexString());
                }
                return;
            }
            if (replyHdr.getXid() == -1)
            {
                // -1 means notification
                if (LOG.isDebugEnabled())
                {
                    LOG.debug("Got notification sessionid:0x"
                              + sessionId.ToHexString());
                }
                WatcherEvent @event = new WatcherEvent();
                ((Record)@event).deserialize(bbia, "response");
                // convert from a server path to a client path
                if (chrootPath != null)
                {
                    string serverPath = @event.getPath();
                    if (serverPath == chrootPath)
                    {
                        @event.setPath("/");
                    }
                    else if (serverPath.Length > chrootPath.Length)
                    {
                        @event.setPath(serverPath.Substring(chrootPath.Length));
                    }
                    else
                    {
                        LOG.warn("Got server path " + @event.getPath()
                                 + " which is too short for chroot path "
                                 + chrootPath);
                    }
                }
                WatchedEvent we = new WatchedEvent(@event);
                if (LOG.isDebugEnabled())
                {
                    LOG.debug("Got " + we + " for sessionid 0x" + sessionId.ToHexString());
                }
                queueEvent(we);
                return;
            }

            Packet packet;

            lock (pendingQueue) {
                if (pendingQueue.size() == 0)
                {
                    throw new IOException("Nothing in the queue, but got "
                                          + replyHdr.getXid());
                }
                packet = pendingQueue.First.Value;
                pendingQueue.RemoveFirst();
            }

            /*
             * Since requests are processed in order, we better get a response
             * to the first request!
             */
            try {
                if (packet.requestHeader.getXid() != replyHdr.getXid())
                {
                    packet.replyHeader.setErr((int)KeeperException.Code.CONNECTIONLOSS);
                    throw new IOException("Xid out of order. Got Xid "
                                          + replyHdr.getXid() + " with err "
                                          + +replyHdr.getErr() + " expected Xid "
                                          + packet.requestHeader.getXid()
                                          + " for a packet with details: " + packet);
                }
                packet.replyHeader.setXid(replyHdr.getXid());
                packet.replyHeader.setErr(replyHdr.getErr());
                packet.replyHeader.setZxid(replyHdr.getZxid());
                if (replyHdr.getZxid() > 0)
                {
                    lastZxid.Value = replyHdr.getZxid();
                }
                if (packet.response != null && replyHdr.getErr() == 0)
                {
                    packet.response.deserialize(bbia, "response");
                }
                if (LOG.isDebugEnabled())
                {
                    LOG.debug("Reading reply sessionid:0x" + sessionId.ToHexString() + ", packet:: " +
                              packet);
                }
            }
            finally {
                finishPacket(packet);
            }
        }
Пример #5
0
 public WatcherSetEventPair(HashSet <Watcher> watchers, WatchedEvent @event)
 {
     this.watchers = watchers;
     this.@event   = @event;
 }
Пример #6
0
 /// <summary>
 /// Processes the specified event.
 /// </summary>
 /// <param name="event">The event.</param>
 /// <returns></returns>
 public abstract Task process(WatchedEvent @event);
Пример #7
0
 public override Task process(WatchedEvent @event)
 {
     return(processor(@event));
 }
Пример #8
0
 //-------------------------------------------------------------------------
 public override Task process(org.apache.zookeeper.WatchedEvent @event)
 {
     return(TaskDone.Done);
 }