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

public final Class QuicClient

extends Object
implements QuicInstance, AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable, jdk.internal.net.http.quic.QuicInstance
Imports
java.io.IOException, java.net.InetSocketAddress, .SocketAddress, java.nio.ByteBuffer, java.util.ArrayList, .Arrays, .List, .Map, .Objects, java.util.concurrent.ConcurrentHashMap, .Executor, java.util.concurrent.atomic.AtomicLong, java.util.concurrent.locks.ReentrantLock, java.util.function.LongFunction, javax.net.ssl.SSLParameters, jdk.internal.net.http.AltServicesRegistry, jdk.internal.net.http.common.Log, .Logger, .Utils, jdk.internal.net.http.quic.QuicEndpoint.QuicEndpointFactory, jdk.internal.net.http.quic.packets.QuicPacket, jdk.internal.net.quic.QuicTLSContext, .QuicVersion

This class represents a QuicClient. The QuicClient is responsible for creating/returning instances of QuicConnection for a given AltService, and for linking them with an instance of QuicEndpoint and QuicSelector for reading and writing Datagrams off the network. A QuicClient is also a factory for QuicConnectionIds. There is a 1-1 relationship between a QuicClient and an Http3Client. A QuicClient can be closed: closing a QuicClient will close all quic connections opened on that client.
External Specification
https://www.rfc-editor.org/info/rfc9000, https://www.rfc-editor.org/info/rfc9369

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
private static record

Field Summary

Modifier and TypeField and Description
private final LongFunction<String>
private final List<QuicVersion>
private final InetSocketAddress
private final String
private volatile boolean
private static final AtomicLong
private final Logger
pack-priv static final int
private final QuicEndpoint.QuicEndpointFactory
private final QuicEndpoint[]
private final Executor
private static final AtomicLong
pack-priv static final int
private final Map<QuicClient.InitialTokenRecipient, byte[]>
private int
private final ReentrantLock
pack-priv static final int
private final String
private final QuicTLSContext
private volatile QuicSelector<?>
pack-priv static final int
private final SSLParameters
private final QuicTransportParameters

Constructor Summary

AccessConstructor and Description
private
QuicClient(final QuicClient.Builder builder)

Method Summary

Modifier and TypeMethod and Description
public void
private void
public String
appErrorToString(long code)

Overrides default jdk.internal.net.http.quic.QuicInstance.appErrorToString.

Returns a string describing the given application error code.

public InetSocketAddress

Returns:

the address that the QuicEndpoint will bind to.
bindAddress
()

The address that the QuicEndpoint will bind to.

private QuicEndpoint
public String

Returns:

A string identifying the HttpClientImpl instance.
clientId
()

The HttpClientImpl Id. used to identify the client in debug traces.

public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

private void
private static int
public QuicConnectionImpl

Returns:

a new unconnected QuicConnection
createConnectionFor
(final AltServicesRegistry.AltService
the alternate service for which to create the connection for
service
)

Creates a new unconnected QuicConnection to the given service.

public QuicConnectionImpl

Returns:

a new unconnected QuicConnection
createConnectionFor
(final InetSocketAddress
the address of the peer
peerAddress
,
final String[] alpns)

Creates a new unconnected QuicConnection to the given peerAddress.

private QuicEndpoint

Returns:

the new QuicEndpoint
createEndpoint
(final String endpointName)

Creates an endpoint with the given name, and register it with a selector.

private SSLParameters
createSSLParameters(final String[] alpns)

public Executor

Returns:

the executor used by this QuicClient.
executor
()

Implements jdk.internal.net.http.quic.QuicInstance.executor.

The executor used by this QuicClient when a task needs to be offloaded to a separate thread.

public List<QuicVersion>

Returns:

the versions that are available for use on this instance, in the descending order of their preference
getAvailableVersions
()

Implements jdk.internal.net.http.quic.QuicInstance.getAvailableVersions.

Returns the versions that are available for use on this instance, in the descending order of their preference.

public QuicEndpoint
getEndpoint()

Implements jdk.internal.net.http.quic.QuicInstance.getEndpoint.

Returns an endpoint to associate with a connection.

public QuicTLSContext
getQuicTLSContext()

Implements jdk.internal.net.http.quic.QuicInstance.getQuicTLSContext.

Get the QuicTLSContext used by this quic instance.

public SSLParameters
public QuicTransportParameters
pack-priv byte[]
initialTokenFor(final InetSocketAddress
The address of the server
peerAddress
)

Returns: the initial token to use in INITIAL packets during connection establishment against a server represented by the peerAddress.

public String
instanceId()

Implements jdk.internal.net.http.quic.QuicInstance.instanceId.

Instance ID used for debugging traces.

public boolean
isVersionAvailable(final QuicVersion quicVersion)

Implements jdk.internal.net.http.quic.QuicInstance.isVersionAvailable.

Returns true if the passed version is available for use on this instance, false otherwise.

public String

Returns:

the name identifying this QuicClient.
name
()

Overrides default jdk.internal.net.http.quic.QuicInstance.name.

The name identifying this QuicClient, used in debug traces.

private static String
pack-priv void
registerInitialToken(final InetSocketAddress
The address of the server
peerAddress
,
final byte[]
The token to use
token
)

Registers a token to use in INITIAL packets during connection establishment against a server represented by the peerAddress.

private static SSLParameters
requireTLS13(final SSLParameters parameters)

public void
unmatchedQuicPacket(SocketAddress source, QuicPacket.HeadersType type, ByteBuffer buffer)

Implements jdk.internal.net.http.quic.QuicInstance.unmatchedQuicPacket.

This method is called when a quic packet that couldn't be attributed to a registered connection is received.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

appErrorCodeToStringback to summary
private final LongFunction<String> appErrorCodeToString
availableVersionsback to summary
private final List<QuicVersion> availableVersions
bindAddressback to summary
private final InetSocketAddress bindAddress
clientIdback to summary
private final String clientId
closedback to summary
private volatile boolean closed
CONNECTIONSback to summary
private static final AtomicLong CONNECTIONS
debugback to summary
private final Logger debug
DEFAULT_MAX_ENDPOINTSback to summary
pack-priv static final int DEFAULT_MAX_ENDPOINTS
endpointFactoryback to summary
private final QuicEndpoint.QuicEndpointFactory endpointFactory
endpointsback to summary
private final QuicEndpoint[] endpoints
executorback to summary
private final Executor executor
IDSback to summary
private static final AtomicLong IDS
INITIAL_SERVER_CONNECTION_ID_LENGTHback to summary
pack-priv static final int INITIAL_SERVER_CONNECTION_ID_LENGTH
initialTokensback to summary
private final Map<QuicClient.InitialTokenRecipient, byte[]> initialTokens
insertionPointback to summary
private int insertionPoint
lockback to summary
private final ReentrantLock lock
MAX_ENDPOINTS_LIMITback to summary
pack-priv static final int MAX_ENDPOINTS_LIMIT
nameback to summary
private final String name
quicTLSContextback to summary
private final QuicTLSContext quicTLSContext
selectorback to summary
private volatile QuicSelector<?> selector
SMALLEST_MAXIMUM_DATAGRAM_SIZEback to summary
pack-priv static final int SMALLEST_MAXIMUM_DATAGRAM_SIZE
sslParametersback to summary
private final SSLParameters sslParameters
transportParamsback to summary
private final QuicTransportParameters transportParams

Constructor Detail

QuicClientback to summary
private QuicClient(final QuicClient.Builder builder)

Method Detail

abortback to summary
public void abort(Throwable t)
abortEndpointback to summary
private void abortEndpoint(QuicEndpoint endpoint, Throwable cause)
appErrorToStringback to summary
public String appErrorToString(long code)

Overrides default jdk.internal.net.http.quic.QuicInstance.appErrorToString.

Doc from jdk.internal.net.http.quic.QuicInstance.appErrorToString.

Returns a string describing the given application error code.

Annotations
@Override
bindAddressback to summary
public InetSocketAddress bindAddress()

The address that the QuicEndpoint will bind to.

Implementation Note

By default, this is wildcard:0

Returns:InetSocketAddress

the address that the QuicEndpoint will bind to.

chooseEndpointback to summary
private QuicEndpoint chooseEndpoint() throws IOException
clientIdback to summary
public String clientId()

The HttpClientImpl Id. used to identify the client in debug traces.

Returns:String

A string identifying the HttpClientImpl instance.

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
closeEndpointback to summary
private void closeEndpoint(QuicEndpoint endpoint)
computeMaxEndpointsback to summary
private static int computeMaxEndpoints()
createConnectionForback to summary
public QuicConnectionImpl createConnectionFor(final AltServicesRegistry.AltService service)

Creates a new unconnected QuicConnection to the given service.

API Note

The caller is expected to call QuicConnectionImpl#startHandshake() to initiate the handshaking. The connection is considered "connected" when the handshake is successfully completed.

Parameters
service:AltServicesRegistry.AltService

the alternate service for which to create the connection for

Returns:QuicConnectionImpl

a new unconnected QuicConnection

Exceptions
IllegalArgumentException:
if the ALPN of this transport isn't the same as that of the passed alternate service
createConnectionForback to summary
public QuicConnectionImpl createConnectionFor(final InetSocketAddress peerAddress, final String[] alpns)

Creates a new unconnected QuicConnection to the given peerAddress.

API Note

The caller is expected to call QuicConnectionImpl#startHandshake() to initiate the handshaking. The connection is considered "connected" when the handshake is successfully completed.

Parameters
peerAddress:InetSocketAddress

the address of the peer

Returns:QuicConnectionImpl

a new unconnected QuicConnection

createEndpointback to summary
private QuicEndpoint createEndpoint(final String endpointName) throws IOException

Creates an endpoint with the given name, and register it with a selector.

Returns:QuicEndpoint

the new QuicEndpoint

Exceptions
IOException:
if an error occurs when setting up the selector or linking the transport with the selector.
IllegalStateException:
if the client is closed.
createSSLParametersback to summary
private SSLParameters createSSLParameters(final String[] alpns)
executorback to summary
public Executor executor()

Implements jdk.internal.net.http.quic.QuicInstance.executor.

The executor used by this QuicClient when a task needs to be offloaded to a separate thread.

Implementation Note

This is the HttpClientImpl internal executor.

Returns:Executor

the executor used by this QuicClient.

Annotations
@Override
getAvailableVersionsback to summary
public List<QuicVersion> getAvailableVersions()

Implements jdk.internal.net.http.quic.QuicInstance.getAvailableVersions.

Returns the versions that are available for use on this instance, in the descending order of their preference.

Returns:List<QuicVersion>

the versions that are available for use on this instance, in the descending order of their preference

Annotations
@Override
getEndpointback to summary
public QuicEndpoint getEndpoint() throws IOException

Implements jdk.internal.net.http.quic.QuicInstance.getEndpoint.

Doc from jdk.internal.net.http.quic.QuicInstance.getEndpoint.

Returns an endpoint to associate with a connection.

Annotations
@Override
getQuicTLSContextback to summary
public QuicTLSContext getQuicTLSContext()

Implements jdk.internal.net.http.quic.QuicInstance.getQuicTLSContext.

Doc from jdk.internal.net.http.quic.QuicInstance.getQuicTLSContext.

Get the QuicTLSContext used by this quic instance.

Annotations
@Override
getSSLParametersback to summary
public SSLParameters getSSLParameters()

Overrides default jdk.internal.net.http.quic.QuicInstance.getSSLParameters.

Doc from jdk.internal.net.http.quic.QuicInstance.getSSLParameters.

The SSLParameters for this Quic instance. May be null if no parameters have been specified.

Annotations
@Override
getTransportParametersback to summary
public QuicTransportParameters getTransportParameters()

Implements jdk.internal.net.http.quic.QuicInstance.getTransportParameters.

Annotations
@Override
initialTokenForback to summary
pack-priv byte[] initialTokenFor(final InetSocketAddress peerAddress)
Parameters
peerAddress:InetSocketAddress

The address of the server

Returns:byte[]

the initial token to use in INITIAL packets during connection establishment against a server represented by the peerAddress. Returns null if no token exists for the server.

instanceIdback to summary
public String instanceId()

Implements jdk.internal.net.http.quic.QuicInstance.instanceId.

Doc from jdk.internal.net.http.quic.QuicInstance.instanceId.

Instance ID used for debugging traces.

Annotations
@Override
isVersionAvailableback to summary
public boolean isVersionAvailable(final QuicVersion quicVersion)

Implements jdk.internal.net.http.quic.QuicInstance.isVersionAvailable.

Doc from jdk.internal.net.http.quic.QuicInstance.isVersionAvailable.

Returns true if the passed version is available for use on this instance, false otherwise.

Annotations
@Override
nameback to summary
public String name()

Overrides default jdk.internal.net.http.quic.QuicInstance.name.

The name identifying this QuicClient, used in debug traces.

Implementation Note

This is "QuicClient(<clientId>)".

Returns:String

the name identifying this QuicClient.

nextNameback to summary
private static String nextName()
registerInitialTokenback to summary
pack-priv void registerInitialToken(final InetSocketAddress peerAddress, final byte[] token)

Registers a token to use in INITIAL packets during connection establishment against a server represented by the peerAddress.

Parameters
peerAddress:InetSocketAddress

The address of the server

token:byte[]

The token to use

Exceptions
NullPointerException:
If either of peerAddress or token is null
IllegalArgumentException:
If the token is of zero length
requireTLS13back to summary
private static SSLParameters requireTLS13(final SSLParameters parameters)
unmatchedQuicPacketback to summary
public void unmatchedQuicPacket(SocketAddress source, QuicPacket.HeadersType type, ByteBuffer buffer)

Implements jdk.internal.net.http.quic.QuicInstance.unmatchedQuicPacket.

Doc from jdk.internal.net.http.quic.QuicInstance.unmatchedQuicPacket.

This method is called when a quic packet that couldn't be attributed to a registered connection is received.

Annotations
@Override
jdk.internal.net.http.quic back to summary

public final Class QuicClient.Builder

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private LongFunction<String>
private List<QuicVersion>
private InetSocketAddress
private String
private Executor
private SSLParameters
private QuicTLSContext
private QuicTransportParameters

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public QuicClient.Builder
public QuicClient.Builder
public QuicClient.Builder
availableVersions(final QuicVersion version, final QuicVersion... more)

public QuicClient.Builder
public QuicClient
public QuicClient.Builder
clientId(final String clientId)

public QuicClient.Builder
executor(final Executor executor)

public QuicClient.Builder
sslParameters(final SSLParameters sslParameters)

public QuicClient.Builder
tlsContext(final QuicTLSContext tlsContext)

public QuicClient.Builder
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

appErrorCodeToStringback to summary
private LongFunction<String> appErrorCodeToString
availableVersionsback to summary
private List<QuicVersion> availableVersions
bindAddrback to summary
private InetSocketAddress bindAddr
clientIdback to summary
private String clientId
executorback to summary
private Executor executor
sslParamsback to summary
private SSLParameters sslParams
tlsContextback to summary
private QuicTLSContext tlsContext
transportParamsback to summary
private QuicTransportParameters transportParams

Constructor Detail

Builderback to summary
public Builder()

Method Detail

applicationErrorsback to summary
public QuicClient.Builder applicationErrors(LongFunction<String> errorCodeToString)
availableVersionsback to summary
public QuicClient.Builder availableVersions(final List<QuicVersion> versions)
availableVersionsback to summary
public QuicClient.Builder availableVersions(final QuicVersion version, final QuicVersion... more)
bindAddressback to summary
public QuicClient.Builder bindAddress(final InetSocketAddress bindAddr)
buildback to summary
public QuicClient build()
clientIdback to summary
public QuicClient.Builder clientId(final String clientId)
executorback to summary
public QuicClient.Builder executor(final Executor executor)
sslParametersback to summary
public QuicClient.Builder sslParameters(final SSLParameters sslParameters)
tlsContextback to summary
public QuicClient.Builder tlsContext(final QuicTLSContext tlsContext)
transportParametersback to summary
public QuicClient.Builder transportParameters(final QuicTransportParameters transportParams)
jdk.internal.net.http.quic back to summary

private final Record QuicClient.InitialTokenRecipient

extends Record
Class Inheritance
Record Components
host:String 
port:int 

Field Summary

Modifier and TypeField and Description
private final String
host

Record Component accessed by host().

private final int
port

Record Component accessed by port().

Constructor Summary

AccessConstructor and Description
private
InitialTokenRecipient(String host, int port)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public String
host()

Record Component getter of host.

public int
port()

Record Component getter of port.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

hostback to summary
private final String host

Record Component accessed by host().

portback to summary
private final int port

Record Component accessed by port().

Constructor Detail

InitialTokenRecipientback to summary
private InitialTokenRecipient(String host, int port)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

hostback to summary
public String host()

Record Component getter of host.

portback to summary
public int port()

Record Component getter of port.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.