Class Http2ConnectionState
- java.lang.Object
-
- org.asynchttpclient.netty.channel.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 Summary
Fields Modifier and Type Field Description static io.netty.util.AttributeKey<Http2ConnectionState>HTTP2_STATE_KEY
-
Constructor Summary
Constructors Constructor Description Http2ConnectionState()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPendingOpener(Runnable opener)Binary-compatibility wrapper for thevoid addPendingOpener(Runnable)member released in 3.0.9 (descriptor()V); the branch's change to abooleanreturn was binary-incompatible.voidfailPendingOpeners(Consumer<NettyResponseFuture<?>> failer)Permanently marks the connection unusable and hands every queued (never-started) request tofailer.intgetActiveStreams()intgetLastGoAwayStreamId()intgetMaxConcurrentStreams()ObjectgetPartitionKey()booleanisDraining()booleanisRedundant()voidmarkRedundant()Marks this connection as a redundant duplicate that should close once its last stream ends.booleanofferPendingOpener(Runnable opener)booleanofferPendingOpener(NettyResponseFuture<?> future, Runnable opener)Runsopenerimmediately if a stream slot is free, otherwise queues it for a laterreleaseStream().voidreleaseStream()voidsetClientMaxConcurrentStreams(int clientMaxConcurrentStreams)Sets the client's own configured cap (fromconfig.getHttp2MaxConcurrentStreams()).voidsetDraining(int lastStreamId)voidsetPartitionKey(Object partitionKey)booleantryAcquireStream()voidupdateMaxConcurrentStreams(int serverMaxConcurrentStreams)Applies the server-advertised SETTINGS_MAX_CONCURRENT_STREAMS.
-
-
-
Field Detail
-
HTTP2_STATE_KEY
public static final io.netty.util.AttributeKey<Http2ConnectionState> HTTP2_STATE_KEY
-
-
Method Detail
-
tryAcquireStream
public boolean tryAcquireStream()
-
releaseStream
public void releaseStream()
-
addPendingOpener
public void addPendingOpener(Runnable opener)
Binary-compatibility wrapper for thevoid addPendingOpener(Runnable)member released in 3.0.9 (descriptor()V); the branch's change to abooleanreturn was binary-incompatible. This restores the original member. Delegates toofferPendingOpener(Runnable), ignoring the result; internal callers that must observe the draining/closed rejection (the GOAWAY-orphan fix) useofferPendingOpenerdirectly.
-
offerPendingOpener
public boolean offerPendingOpener(Runnable opener)
-
offerPendingOpener
public boolean offerPendingOpener(NettyResponseFuture<?> future, Runnable opener)
Runsopenerimmediately if a stream slot is free, otherwise queues it for a laterreleaseStream(). Returnsfalse— without queuing — when the connection is already draining or closed, or when the pending queue is already atMAX_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, andfailPendingOpeners(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 setsclosedand drains the queue underpendingLock. An opener enqueued before the drain runs is caught by the drain; an enqueue attempt sequenced after it observesclosedhere (the lock provides the happens-before) and is rejected. Either way no opener is left stranded.- Returns:
trueif the opener was run inline or queued;falseif 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 tofailer. After this calltryAcquireStream()returnsfalse, 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
pendingOpenerswhen 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 (fromconfig.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()
-
-