APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http

pack-priv Class Http2Connection

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .EOFException, .IOException, .UncheckedIOException, java.net.InetSocketAddress, .ProtocolException, java.net.http.HttpClient, .HttpClient.Version, .HttpHeaders, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, java.nio.charset.StandardCharsets, java.time.Duration, java.util.ArrayList, .Iterator, .List, .Locale, .Map, .Objects, java.util.concurrent.CompletableFuture, .ConcurrentHashMap, .ConcurrentLinkedQueue, .Flow, java.util.concurrent.atomic.AtomicBoolean, .AtomicInteger, .AtomicLong, .AtomicReference, java.util.concurrent.locks.Lock, .ReentrantLock, java.util.function.Function, .Supplier, javax.net.ssl.SSLEngine, .SSLException, jdk.internal.net.http.HttpConnection.HttpPublisher, jdk.internal.net.http.common.Alpns, .FlowTube, .FlowTube.TubeSubscriber, .HeaderDecoder, .Log, .Logger, .MinimalFuture, .SequentialScheduler, .Utils, .ValidatingHeadersConsumer, .ValidatingHeadersConsumer.Context, jdk.internal.net.http.frame.AltSvcFrame, .ContinuationFrame, .DataFrame, .ErrorFrame, .FramesDecoder, .FramesEncoder, .GoAwayFrame, .HeaderFrame, .HeadersFrame, .Http2Frame, .MalformedFrame, .OutgoingHeaders, .PingFrame, .PushPromiseFrame, .ResetFrame, .SettingsFrame, .WindowUpdateFrame, jdk.internal.net.http.hpack.Decoder, .DecodingCallback, .Encoder

An Http2Connection. Encapsulates the socket(channel) and any SSLEngine used over it. Contains an HttpConnection which hides the SocketChannel SSL stuff. Http2Connections belong to a Http2ClientImpl, (one of) which belongs to a HttpClientImpl. Creation cases: 1) upgraded HTTP/1.1 plain tcp connection 2) prior knowledge directly created plain tcp connection 3) directly created HTTP/2 SSL connection which uses ALPN. Sending is done by writing directly to underlying HttpConnection object which is operating in async mode. No flow control applies on output at this level and all writes are just executed as puts to an output Q belonging to HttpConnection Flow control is implemented by HTTP/2 protocol itself. Hpack header compression and outgoing stream creation is also done here, because these operations must be synchronized at the socket level. Stream objects send frames simply by placing them on the connection's output Queue. sendFrame() is called from a higher level (Stream) thread. asyncReceive(ByteBuffer) is always called from the selector thread. It assembles incoming Http2Frames, and directs them to the appropriate Stream.incoming() or handles them directly itself. This thread performs hpack decompression and incoming stream creation (Server push). Incoming frames destined for a stream are provided by calling Stream.incoming().

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
Http2Connection.ALPNException

Thrown when https handshake negotiates http/1.1 alpn instead of h2

pack-priv static class
private class
pack-priv class
Http2Connection.Http2TubeSubscriber

A simple tube subscriber for reading from the connection flow.

pack-priv class
private static record
private class
private class

Field Summary

Modifier and TypeField and Description
private final Http2ClientImpl
private static final String
pack-priv final SettingsFrame
pack-priv final HttpConnection
private final Http2Connection.Terminator
pack-priv long
pack-priv final Logger
pack-priv static final Logger
private final Logger
pack-priv static final int
pack-priv static final ByteBuffer
private volatile boolean
finalStream

Flag set when no more streams to be opened on this connection.

private final Http2Connection.FramesController
private final FramesDecoder
private final FramesEncoder
private final AtomicBoolean
private final AtomicBoolean
private final Decoder
private final Encoder
private Http2Connection.IdleConnectionTimeoutEvent
private volatile Supplier<ByteBuffer>
private volatile Stream<?>
private final String
private final AtomicLong
private int
private int
private static final int
pack-priv static final int
pack-priv static final int
private static final int
private int
private int
private int
private int
private ValidatingHeadersConsumer
private final AtomicInteger
private static final byte[]
private volatile Http2Connection.PushContinuationState
private final Lock
private volatile SettingsFrame
private final ReentrantLock
private final ConcurrentHashMap<Integer, Stream<?>>
private final Http2Connection.Http2TubeSubscriber
private final WindowController
windowController

Send Window controller for both connection and stream windows.

pack-priv final Http2Connection.ConnectionWindowUpdateSender

Constructor Summary

AccessConstructor and Description
private
Http2Connection(HttpConnection connection, Http2ClientImpl client2, int nextstreamid, String key, boolean defaultServerPush)

private
Http2Connection(HttpConnection connection, Http2ClientImpl client2, Exchange<?> exchange, Supplier<ByteBuffer> initial, boolean defaultServerPush)

Case 1) Create from upgraded HTTP/1.1 connection.

private
Http2Connection(HttpRequestImpl request, Http2ClientImpl h2client, HttpConnection connection, boolean defaultServerPush)

Cases 2) 3) request is request to be sent.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv final void
private void
cancelIdleCloseEvent()

Cancels any event that might have been scheduled to close this connection.

private String
private static CompletableFuture<?>
checkSSLConfig(AbstractAsyncSSLConnection aconn)

Throws an IOException if h2 was not negotiated

pack-priv final HttpClientImpl
public final void
close()

Implements java.io.Closeable.close.

Closes the connection normally (with a NO_ERROR termination cause), if not already closed.

pack-priv final void
close(final Http2TerminationCause
the termination cause. cannot be null.
tc
)

Closes the connection with the given termination cause, if not already closed.

pack-priv void
pack-priv void
closeStream(int streamid)

private <T> void
completePushPromise(int promisedStreamid, Stream<T> parent, HttpHeaders headers)

private void
pack-priv static CompletableFuture<Http2Connection>
createAsync(HttpConnection connection, Http2ClientImpl client2, Exchange<?> exchange, Supplier<ByteBuffer> initial)

pack-priv static CompletableFuture<Http2Connection>
createAsync(HttpRequestImpl request, Http2ClientImpl h2client, Exchange<?> exchange)

pack-priv <T> Stream.PushedStream<T>
createPushStream(Stream<T> parent, Exchange<T> pushEx)

pack-priv final <T> Stream<T>
createStream(Exchange<T> exchange)

Creates Stream with given id.

pack-priv final String
private void
pack-priv void
decrementStreamsCount(int streamid)

private void
decrementStreamsCount0(int streamid)

pack-priv final void
private List<ByteBuffer>
private List<ByteBuffer>
private List<HeaderFrame>
encodeHeaders(OutgoingHeaders<Stream<?>> frame)

Encode the headers into a List<ByteBuffer> and then create HEADERS and CONTINUATION frames from the list and return the List<Http2Frame>.

private List<ByteBuffer>
private List<ByteBuffer>
encodeHeadersImpl(int bufferSize, HttpHeaders... headers)

pack-priv final void
pack-priv boolean
private ByteBuffer
getHeaderBuffer(int size)

pack-priv final int
pack-priv <
the response type
T
>
Stream<T>

Returns:

the initial stream created during the upgrade.
getInitialStream
()

Called to get the initial stream after a connection upgrade.

public int
getMaxReceiveFrameSize()

Max frame size we will receive

public int
getMaxSendFrameSize()

Max frame size we are allowed to send

pack-priv <T> Stream<T>
getStream(int streamid)

Returns an existing Stream with given id, or null if doesn't exist

pack-priv final Http2TerminationCause
getTerminationCause()

Returns the termination cause if the connection is closed, else returns null.

private void
private void
private void
handlePeerUnprocessedStreams(final long lastProcessedStream)

private void
private <T> void
private <T> void
private void
private void
handleWindowUpdate(WindowUpdateFrame f)

Increments this connection's send Window by the amount in the given frame.

pack-priv boolean
pack-priv final boolean
isOpen()

Returns true if this connection hasn't been terminated and the underlying channel is open.

private static final boolean
isServerInitiatedStream(int streamid)

Streams initiated by a client MUST use odd-numbered stream identifiers; those initiated by the server MUST use even-numbered stream identifiers.

pack-priv String
key()

pack-priv static String
keyFor(HttpConnection connection)

pack-priv static String
keyFor(final HttpRequestImpl request)

pack-priv static String
keyString(boolean secure, InetSocketAddress proxy, String host, int port)

private void
markStream(int streamid, int code)

pack-priv final int
pack-priv final int
pack-priv boolean
pack-priv void
processFrame(Http2Frame frame)

Handles stream 0 (common) frames that apply to whole connection and passes other stream specific frames to that Stream object.

private void
protocolError(final int errorCode, final String msg)

private HttpConnection.HttpPublisher
pack-priv <T> void
putStream(Stream<T> stream, int streamid)

private Stream<?>
pack-priv final void
pack-priv boolean
reserveStream(boolean clientInitiated, boolean pushEnabled)

private boolean
reserveStream0(boolean clientInitiated, boolean pushEnabled)

pack-priv void
resetStream(int streamid, int code)

private void
sendConnectionPreface()

Sends Connection preface and Settings frame with current preferred values

pack-priv void
pack-priv void
private void
sendGoAway(final GoAwayFrame goAway)

pack-priv void
public boolean
pack-priv void
setFinalStream()

Mark this connection so no more streams created on it and it will close when all are complete.

pack-priv final boolean
public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

pack-priv boolean

Returns:

true if the connection has been successfully reserved and is isOpen(). false otherwise; in which case the connection must not be handed out from the pool.
tryReserveForPoolCheckout
()

Attempts to notify the idle connection management that this connection should be considered "in use".

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait