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

public abstract Class QuicConnection

extends Object
Class Inheritance
Known Direct Subclasses
jdk.internal.net.http.quic.QuicConnectionImpl
Imports
java.net.InetSocketAddress, .SocketAddress, java.time.Duration, java.util.concurrent.CompletableFuture, java.util.function.Predicate, java.util.stream.Stream, jdk.internal.net.http.quic.packets.QuicPacket, jdk.internal.net.http.quic.streams.QuicBidiStream, .QuicReceiverStream, .QuicSenderStream, .QuicStream, .QuicStreams, jdk.internal.net.quic.QuicTLSEngine

This class implements a QUIC connection. A QUIC connection is established between a client and a server over a QuicEndpoint endpoint. A QUIC connection can then multiplex multiple QUIC streams to the same server. This abstract class exposes public methods used by the higher level protocol.

A typical call flow to establish a connection would be:

AltService service = ...; QuicClient client = ...; QuicConnection connection = client.createConnectionFor(service); connection.startHandshake() .thenApply((r) -> { ... }) ...;
AltService service = ...;
QuicClient client = ...;
QuicConnection connection = client.createConnectionFor(service);
connection.startHandshake()
.thenApply((r) ->  { ... })
...;

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract void
addRemoteStreamListener(Predicate<? super QuicReceiverStream>
the listener
streamConsumer
)

Adds a listener that will be invoked when a remote stream is created.

public abstract ConnectionTerminator

Returns:

the ConnectionTerminator for this connection
connectionTerminator
()

Returns the ConnectionTerminator for this connection.

public abstract String

Returns:

a debug tag to be used with lower level logging
dbgTag
()

Returns a debug tag to be used with lower level logging.

public abstract QuicTLSEngine
public abstract CompletableFuture<Void>
handshakeReachedPeer()

{@return a CompletableFuture that gets completed when the peer has acknowledged, or replied to the first INITIAL packet

public abstract boolean

Returns:

true if this connection is open
isOpen
()

Returns true if this connection is open.

public abstract SocketAddress
public QuicConnectionId

Returns:

this connection QuicConnectionId or null
localConnectionId
()

Returns this connection QuicConnectionId or null.

public abstract String

Returns:

a debug tag
logTag
()

Returns a debug tag.

public abstract CompletableFuture<QuicBidiStream>

Returns:

a CompletableFuture which completes either with a new locally initiated bidirectional stream or exceptionally if the stream creation failed
openNewLocalBidiStream
(Duration
Amount of time to wait for the bidirectional stream creation limit to be increased by the peer, if this connection has currently reached its limit
limitIncreaseDuration
)

Creates a new locally initiated bidirectional stream.

public abstract CompletableFuture<QuicSenderStream>

Returns:

a CompletableFuture which completes either with a new locally initiated unidirectional stream or exceptionally if the stream creation failed
openNewLocalUniStream
(Duration
Amount of time to wait for the unidirectional stream creation limit to be increased by the peer, if this connection has currently reached its limit
limitIncreaseDuration
)

Creates a new locally initiated unidirectional stream.

public abstract InetSocketAddress
public abstract Stream<? extends QuicStream>

Returns:

a stream of all currently opened QuicStream in the connection
quicStreams
()

Returns a stream of all currently opened QuicStream in the connection.

public abstract boolean

Returns:

true if the listener was found and removed, false otherwise
removeRemoteStreamListener
(Predicate<? super QuicReceiverStream> streamConsumer)

Removes a listener previously added with addRemoteStreamListener(Predicate)

public abstract CompletableFuture<Long>

Returns:

A completable future that will be completed with the number of milliseconds it took to get a valid response. It may also complete exceptionally, or with -1L if the ping was not sent.
requestSendPing
()

Requests to send a PING frame to the peer.

public abstract CompletableFuture<QuicEndpoint>

Returns:

A completable future which will be completed when the handshake is completed.
startHandshake
()

Starts the Quic Handshake.

public abstract TerminationCause

Returns:

the TerminationCause if the connection has closed or is being closed, otherwise returns null
terminationCause
()

Returns the TerminationCause if the connection has closed or is being closed, otherwise returns null.

public long

Returns:

a long identifier that can be used to uniquely identify a quic connection in the context of the QuicInstance that created it
uniqueId
()

Returns a long identifier that can be used to uniquely identify a quic connection in the context of the QuicInstance that created it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

QuicConnectionback to summary
public QuicConnection()

Method Detail

addRemoteStreamListenerback to summary
public abstract void addRemoteStreamListener(Predicate<? super QuicReceiverStream> streamConsumer)

Adds a listener that will be invoked when a remote stream is created.

API Note

The listener will be invoked with any remote streams already opened, and not yet acquired by another listener. Any stream passed to the listener is either a QuicBidiStream or a QuicReceiverStream depending on the stream type of the given streamId. The listener should return true if it wishes to acquire the stream.

Parameters
streamConsumer:Predicate<? super QuicReceiverStream>

the listener

connectionTerminatorback to summary
public abstract ConnectionTerminator connectionTerminator()

Returns the ConnectionTerminator for this connection.

Returns:ConnectionTerminator

the ConnectionTerminator for this connection

dbgTagback to summary
public abstract String dbgTag()

Returns a debug tag to be used with lower level logging. This typically includes both the connection uniqueId() and the QuicInstance#instanceId().

Returns:String

a debug tag to be used with lower level logging

getTLSEngineback to summary
public abstract QuicTLSEngine getTLSEngine()
handshakeReachedPeerback to summary
public abstract CompletableFuture<Void> handshakeReachedPeer()

{@return a CompletableFuture that gets completed when the peer has acknowledged, or replied to the first INITIAL packet

isOpenback to summary
public abstract boolean isOpen()

Returns true if this connection is open.

Returns:boolean

true if this connection is open

localAddressback to summary
public abstract SocketAddress localAddress()
localConnectionIdback to summary
public QuicConnectionId localConnectionId()

Returns this connection QuicConnectionId or null.

Implementation Specification

The default implementation of this method returns null

Returns:QuicConnectionId

this connection QuicConnectionId or null

logTagback to summary
public abstract String logTag()

Returns a debug tag. Typically used with higher level logging

Returns:String

a debug tag

openNewLocalBidiStreamback to summary
public abstract CompletableFuture<QuicBidiStream> openNewLocalBidiStream(Duration limitIncreaseDuration)

Creates a new locally initiated bidirectional stream.

Creation of streams is limited to the maximum limit advertised by the peer. If a new stream cannot be created due to this limitation, then this method will use the limitIncreaseDuration to decide how long to wait for a potential increase in the limit.

If the limit has been reached and the limitIncreaseDuration is not positive then this method returns a CompletableFuture which has been completed exceptionally with QuicStreamLimitException. Else, this method returns a CompletableFuture which waits for that duration for a potential increase in the limit. If, during this period, the stream creation limit does increase and stream creation succeeds then the returned CompletableFuture will be completed successfully, else it will complete exceptionally with QuicStreamLimitException.

Parameters
limitIncreaseDuration:Duration

Amount of time to wait for the bidirectional stream creation limit to be increased by the peer, if this connection has currently reached its limit

Returns:CompletableFuture<QuicBidiStream>

a CompletableFuture which completes either with a new locally initiated bidirectional stream or exceptionally if the stream creation failed

openNewLocalUniStreamback to summary
public abstract CompletableFuture<QuicSenderStream> openNewLocalUniStream(Duration limitIncreaseDuration)

Creates a new locally initiated unidirectional stream. Locally created unidirectional streams are write-only streams.

Creation of streams is limited to the maximum limit advertised by the peer. If a new stream cannot be created due to this limitation, then this method will use the limitIncreaseDuration to decide how long to wait for a potential increase in the limit.

If the limit has been reached and the limitIncreaseDuration is not positive then this method returns a CompletableFuture which has been completed exceptionally with QuicStreamLimitException. Else, this method returns a CompletableFuture which waits for that duration for a potential increase in the limit. If, during this period, the stream creation limit does increase and stream creation succeeds then the returned CompletableFuture will be completed successfully, else it will complete exceptionally with QuicStreamLimitException.

Parameters
limitIncreaseDuration:Duration

Amount of time to wait for the unidirectional stream creation limit to be increased by the peer, if this connection has currently reached its limit

Returns:CompletableFuture<QuicSenderStream>

a CompletableFuture which completes either with a new locally initiated unidirectional stream or exceptionally if the stream creation failed

peerAddressback to summary
public abstract InetSocketAddress peerAddress()
quicStreamsback to summary
public abstract Stream<? extends QuicStream> quicStreams()

Returns a stream of all currently opened QuicStream in the connection.

API Note

All current quic streams are included, whether local or remote, and whether they have been acquired or not.

Returns:Stream<? extends QuicStream>

a stream of all currently opened QuicStream in the connection

See Also
addRemoteStreamListener(Predicate)
removeRemoteStreamListenerback to summary
public abstract boolean removeRemoteStreamListener(Predicate<? super QuicReceiverStream> streamConsumer)

Removes a listener previously added with addRemoteStreamListener(Predicate)

Returns:boolean

true if the listener was found and removed, false otherwise

requestSendPingback to summary
public abstract CompletableFuture<Long> requestSendPing()

Requests to send a PING frame to the peer. An implementation may decide to support sending of out-of-band ping frames (triggered by the application layer) only for a subset of the packet number spaces. It may complete with -1 if it doesn't want to request sending of a ping frame at the time requestSendPing() is called.

Returns:CompletableFuture<Long>

A completable future that will be completed with the number of milliseconds it took to get a valid response. It may also complete exceptionally, or with -1L if the ping was not sent.

startHandshakeback to summary
public abstract CompletableFuture<QuicEndpoint> startHandshake()

Starts the Quic Handshake.

Returns:CompletableFuture<QuicEndpoint>

A completable future which will be completed when the handshake is completed.

Exceptions
UnsupportedOperationException:
If this connection isn't a client connection
terminationCauseback to summary
public abstract TerminationCause terminationCause()

Returns the TerminationCause if the connection has closed or is being closed, otherwise returns null.

Returns:TerminationCause

the TerminationCause if the connection has closed or is being closed, otherwise returns null

uniqueIdback to summary
public long uniqueId()

Returns a long identifier that can be used to uniquely identify a quic connection in the context of the QuicInstance that created it.

Returns:long

a long identifier that can be used to uniquely identify a quic connection in the context of the QuicInstance that created it