Beispiel #1
0
        private long BlockReadingForOrderReponse(IChannelHandlerContext ctx)
        {
            long requestSequenceId = Interlocked.Increment(ref _dispatcherSequenceId);

            if (DispatcherContext.IsResponseOrderingRequired(ctx))
            {
                lock (_responseMap)
                {
                    // Limit the number of pending responses (responses which finished out of order, and are
                    // waiting for previous requests to be finished so they can be written in order), by
                    // blocking further channel reads. Due to the way Netty frame decoders work, this is more
                    // of an estimate than a hard limit. Netty may continue to decode and process several
                    // more requests that were in the latest read, even while further reads on the channel
                    // have been blocked.
                    if (requestSequenceId > Interlocked.Read(ref _lastResponseWrittenId) + _queuedResponseLimit &&
                        !DispatcherContext.IsChannelReadBlocked(ctx))
                    {
                        DispatcherContext.BlockChannelReads(ctx);
                    }
                }
            }

            return(requestSequenceId);
        }