Class Http2ConnectionState


  • public class Http2ConnectionState
    extends Object
    Tracks per-connection HTTP/2 state: active stream count, max concurrent streams, draining status (from GOAWAY), and pending stream openers.
    • Field Detail

      • HTTP2_STATE_KEY

        public static final io.netty.util.AttributeKey<Http2ConnectionState> HTTP2_STATE_KEY
    • Constructor Detail

      • Http2ConnectionState

        public Http2ConnectionState()
    • Method Detail

      • tryAcquireStream

        public boolean tryAcquireStream()
      • releaseStream

        public void releaseStream()
      • addPendingOpener

        public void addPendingOpener​(Runnable opener)
        Binary-compatibility wrapper for the void addPendingOpener(Runnable) member released in 3.0.9 (descriptor ()V); the branch's change to a boolean return was binary-incompatible. This restores the original member. Delegates to offerPendingOpener(Runnable), ignoring the result; internal callers that must observe the draining/closed rejection (the GOAWAY-orphan fix) use offerPendingOpener directly.
      • offerPendingOpener

        public boolean offerPendingOpener​(Runnable opener)
      • offerPendingOpener

        public boolean offerPendingOpener​(NettyResponseFuture<?> future,
                                          Runnable opener)
        Runs opener immediately if a stream slot is free, otherwise queues it for a later releaseStream(). Returns falsewithout queuing — when the connection is already draining or closed, or when the pending queue is already at MAX_PENDING_OPENERS: in each case the caller MUST fail the request itself rather than let it sit until the request timeout fires (Issue #2160). A draining/closed connection never runs a queued opener (drainPendingOpeners() only re-offers it, and failPendingOpeners(java.util.function.Consumer<org.asynchttpclient.netty.NettyResponseFuture<?>>) has already drained the queue); a full queue means the peer is starving slots and the request would otherwise grow heap without bound.

        Race-free against failPendingOpeners(java.util.function.Consumer<org.asynchttpclient.netty.NettyResponseFuture<?>>): that method sets closed and drains the queue under pendingLock. An opener enqueued before the drain runs is caught by the drain; an enqueue attempt sequenced after it observes closed here (the lock provides the happens-before) and is rejected. Either way no opener is left stranded.

        Returns:
        true if the opener was run inline or queued; false if rejected because the connection is draining/closed or the pending queue is full (caller must fail the request)
      • failPendingOpeners

        public void failPendingOpeners​(Consumer<NettyResponseFuture<?>> failer)
        Permanently marks the connection unusable and hands every queued (never-started) request to failer. After this call tryAcquireStream() returns false, so a request enqueued concurrently with the close is failed by its own caller's post-enqueue active-channel check rather than being silently orphaned.

        Without this, requests sitting in pendingOpeners when the parent connection drops are never completed and survive only until the request timeout fires — the silent-timeout regression of Issue #2160 (a queued request has no stream channel, hence no channelInactive is ever delivered for it).

        Parameters:
        failer - invoked once per orphaned request future (e.g. to abort it)
      • setClientMaxConcurrentStreams

        public void setClientMaxConcurrentStreams​(int clientMaxConcurrentStreams)
        Sets the client's own configured cap (from config.getHttp2MaxConcurrentStreams()). The effective limit becomes the min of this and any server-advertised value.
      • updateMaxConcurrentStreams

        public void updateMaxConcurrentStreams​(int serverMaxConcurrentStreams)
        Applies the server-advertised SETTINGS_MAX_CONCURRENT_STREAMS. The effective limit is the min of this and the client's configured cap — a server raising its limit never overrides the client's.
      • getMaxConcurrentStreams

        public int getMaxConcurrentStreams()
      • getActiveStreams

        public int getActiveStreams()
      • isDraining

        public boolean isDraining()
      • markRedundant

        public void markRedundant()
        Marks this connection as a redundant duplicate that should close once its last stream ends.
      • isRedundant

        public boolean isRedundant()
      • setDraining

        public void setDraining​(int lastStreamId)
      • getLastGoAwayStreamId

        public int getLastGoAwayStreamId()
      • setPartitionKey

        public void setPartitionKey​(Object partitionKey)
      • getPartitionKey

        public Object getPartitionKey()