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

pack-priv final Class Http3PushManager

extends Object
Class Inheritance
Imports
java.io.IOException, java.net.ProtocolException, java.net.http.HttpHeaders, .HttpResponse, .HttpResponse.BodyHandler, .HttpResponse.PushPromiseHandler.PushId, java.util.Objects, java.util.concurrent.CompletableFuture, .ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, java.util.concurrent.locks.ReentrantLock, jdk.internal.net.http.common.Logger, .MinimalFuture, .Utils, jdk.internal.net.http.http3.Http3Error, jdk.internal.net.http.quic.streams.QuicReceiverStream

Manages HTTP/3 push promises for an HTTP/3 connection.

This class maintains a bounded collection of recent push promises, together with the current state of the promise: pending, processed, or cancelled. When a new jdk.internal.net.http.http3.frames.PushPromiseFrame is received, and entry is added in the map, and the state of the promise is updated as it goes. When the map is full, old entries (lowest pushId) are expunged from the map. No promise will be accepted if its pushId is lower than the lowest pushId in the map.

API Note

When a PushPromiseFrame is received, onPushPromiseFrame(Http3ExchangeImpl, long, HttpHeaders) is called. This arranges for an entry to be added to the map, unless there's already one. Also, the first Http3ExchangeImpl for which this method is called for a given pushId gets to handle the PushPromise: its java.net.http.HttpResponse.PushPromiseHandler will be invoked to accept the promise and handle the body.

When a new PushStream is opened, onPushPromiseStream(QuicReceiverStream, long) is called. When both onPushPromiseFrame and onPushPromiseStream have been called for a given pushId, an Http3PushPromiseStream is created and started to receive the body.

Http3ExchangeImpl that receive a push promise frame, but don't get to handle the body (because it's already been delegated to another stream) should call whenAccepted(long) to figure out when it is safe to invoke PushGroup#acceptPushPromiseId(PushId).

cancelPushPromise(long, Throwable, CancelPushReason) can be called to cancel a push promise. pushPromiseProcessed(long) should be called when the body has been fully processed.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
Http3PushManager.CancelledPushPromise

Represent a PushPromise that has been cancelled.

pack-priv static enum
private static class
Http3PushManager.PendingPushPromise<
the type of the body
T
>

Represents a PushPromise whose body has not been delivered yet.

private static record
Http3PushManager.ProcessedPushPromise

Represent a PushPromise whose body as already been delivered

private static interface
Http3PushManager.PushPromise

A PushPromise can be a PendingPushPromise, until the push response is completely received, or a ProcessedPushPromise, which replace the PendingPushPromise after the response body has been delivered.

Field Summary

Modifier and TypeField and Description
private final CompletableFuture<Boolean>
private final Http3Connection
private final Logger
private final CompletableFuture<Boolean>
private static final long
private static final long
private final AtomicLong
private final AtomicLong
private final AtomicLong
private final AtomicInteger
private final ReentrantLock
private final ConcurrentHashMap<Long, Http3PushManager.PushPromise>
private volatile boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private <U> Http3PushManager.PendingPushPromise<U>
addPushPromise(Http3ExchangeImpl<U> exchange, long pushId, HttpHeaders promiseHeaders)

private <U> Http3PushManager.PendingPushPromise<U>
addPushPromise(QuicReceiverStream stream, long pushId)

public void
private void
pack-priv void
cancelPushPromise(long
the promise pushId
pushId
,
Throwable
the cause (can be null)
cause
,
Http3PushManager.CancelPushReason
reason for cancelling
reason
)

Cancel a push promise.

private void
pack-priv IOException

Returns:

an IOException that can be used to complete a completable future if the maximum pushId is exceeded, null otherwise
checkMaxPushId
(long
the pushId
pushId
)

Checks whether the given pushId exceed the maximum pushId allowed to the peer, and if so, closes the connection.

pack-priv void
checkSendMaxPushId()

Checks whether a MAX_PUSH_ID frame needs to be sent, and send it.

private <U> Http3PushPromiseStream<U>
pack-priv String
pack-priv long

Returns:

the maximum pushId that can be accepted from the peer
getMaxPushId
()

Returns the maximum pushId that can be accepted from the peer.

pack-priv long

Returns:

the minimum pushId that can be accepted from the peer
getMinPushId
()

Returns the minimum pushId that can be accepted from the peer.

pack-priv <U> boolean

Returns:

true if the exchange should take care of creating the HttpResponse body, false otherwise
onPushPromiseFrame
(Http3ExchangeImpl<U>
The HTTP/3 exchange that received the frame
exchange
,
long
The pushId contained in the frame
pushId
,
HttpHeaders
The push promise headers contained in the frame
promiseHeaders
)

Called when a PushPromiseFrame has been decoded.

pack-priv void
onPushPromiseStream(QuicReceiverStream
the new push promise stream
pushStream
,
long
the pushId
pushId
)

Called when a new push promise stream is created by the peer, and the pushId has been read.

pack-priv void
pushPromiseProcessed(long
the pushId
pushId
)

Called when a push promise response body has been successfully received.

private <U> void
pack-priv CompletableFuture<Boolean>

Returns:

a completable future that will be completed when a pushId has been accepted by the exchange in charge of creating the response body
whenAccepted
(long
the pushId
pushId
)

Returns a completable future that will be completed when a pushId has been accepted by the exchange in charge of creating the response body.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ACCEPTEDback to summary
private final CompletableFuture<Boolean> ACCEPTED
connectionback to summary
private final Http3Connection connection
debugback to summary
private final Logger debug
DENIEDback to summary
private final CompletableFuture<Boolean> DENIED
MAX_PUSH_HISTORY_SIZEback to summary
private static final long MAX_PUSH_HISTORY_SIZE
MAX_PUSH_ID_INCREMENTSback to summary
private static final long MAX_PUSH_ID_INCREMENTS
maxPushIdback to summary
private final AtomicLong maxPushId
maxPushReceivedback to summary
private final AtomicLong maxPushReceived
minPushIdback to summary
private final AtomicLong minPushId
pendingPromisesback to summary
private final AtomicInteger pendingPromises
promiseLockback to summary
private final ReentrantLock promiseLock
promisesback to summary
private final ConcurrentHashMap<Long, Http3PushManager.PushPromise> promises
pushPromisesBlockedback to summary
private volatile boolean pushPromisesBlocked

Constructor Detail

Http3PushManagerback to summary
pack-priv Http3PushManager(Http3Connection connection)

Method Detail

addPushPromiseback to summary
private <U> Http3PushManager.PendingPushPromise<U> addPushPromise(Http3ExchangeImpl<U> exchange, long pushId, HttpHeaders promiseHeaders)
addPushPromiseback to summary
private <U> Http3PushManager.PendingPushPromise<U> addPushPromise(QuicReceiverStream stream, long pushId)
cancelAllPromisesback to summary
public void cancelAllPromises(IOException closeCause, Http3Error error)
cancelPendingPushPromiseback to summary
private void cancelPendingPushPromise(Http3PushManager.PendingPushPromise<?> ppp, Throwable cause)
cancelPushPromiseback to summary
pack-priv void cancelPushPromise(long pushId, Throwable cause, Http3PushManager.CancelPushReason reason)

Cancel a push promise. In case of concurrent requests receiving the same pushId, where one has a PushPromiseHandler and the other doesn't, we will cancel the push only if reason != CANCEL_RECEIVED, or no request stream has already accepted the push.

Parameters
pushId:long

the promise pushId

cause:Throwable

the cause (can be null)

reason:Http3PushManager.CancelPushReason

reason for cancelling

checkExpungePromiseMapback to summary
private void checkExpungePromiseMap()
checkMaxPushIdback to summary
pack-priv IOException checkMaxPushId(long pushId)

Checks whether the given pushId exceed the maximum pushId allowed to the peer, and if so, closes the connection.

Parameters
pushId:long

the pushId

Returns:IOException

an IOException that can be used to complete a completable future if the maximum pushId is exceeded, null otherwise

checkSendMaxPushIdback to summary
pack-priv void checkSendMaxPushId()

Checks whether a MAX_PUSH_ID frame needs to be sent, and send it. Called from Http3Connection#checkSendMaxPushId().

createPushExchangeback to summary
private <U> Http3PushPromiseStream<U> createPushExchange(Http3PushManager.PendingPushPromise<U> promise) throws IOException
dbgTagback to summary
pack-priv String dbgTag()
getMaxPushIdback to summary
pack-priv long getMaxPushId()

Returns the maximum pushId that can be accepted from the peer. This corresponds to the pushId that has been included in the last MAX_PUSH_ID frame sent to the peer. A pushId greater than this value must be rejected, and cause the connection to close with error.

API Note

due to internal constraints it is possible that the MAX_PUSH_ID frame has not been sent yet, but the Http3PushManager will behave as if the peer had received that frame.

Returns:long

the maximum pushId that can be accepted from the peer

See Also
Http3Connection#checkMaxPushId(long), checkMaxPushId(long)
getMinPushIdback to summary
pack-priv long getMinPushId()

Returns the minimum pushId that can be accepted from the peer. Any pushId strictly less than this value must be ignored.

API Note

The minimum pushId represents the smallest pushId that was recorded in our history. For smaller pushId, no history has been kept, due to history size constraints. Any pushId strictly less than this value must be ignored.

Returns:long

the minimum pushId that can be accepted from the peer

onPushPromiseFrameback to summary
pack-priv <U> boolean onPushPromiseFrame(Http3ExchangeImpl<U> exchange, long pushId, HttpHeaders promiseHeaders) throws IOException

Called when a PushPromiseFrame has been decoded.

Parameters
exchange:Http3ExchangeImpl<U>

The HTTP/3 exchange that received the frame

pushId:long

The pushId contained in the frame

promiseHeaders:HttpHeaders

The push promise headers contained in the frame

Returns:boolean

true if the exchange should take care of creating the HttpResponse body, false otherwise

See Also
Http3Connection#onPushPromiseFrame(Http3ExchangeImpl, long, HttpHeaders)
onPushPromiseStreamback to summary
pack-priv void onPushPromiseStream(QuicReceiverStream pushStream, long pushId)

Called when a new push promise stream is created by the peer, and the pushId has been read.

Parameters
pushStream:QuicReceiverStream

the new push promise stream

pushId:long

the pushId

pushPromiseProcessedback to summary
pack-priv void pushPromiseProcessed(long pushId)

Called when a push promise response body has been successfully received.

Parameters
pushId:long

the pushId

tryReceivePromiseback to summary
private <U> void tryReceivePromise(Http3PushManager.PendingPushPromise<U> promise)
whenAcceptedback to summary
pack-priv CompletableFuture<Boolean> whenAccepted(long pushId)

Returns a completable future that will be completed when a pushId has been accepted by the exchange in charge of creating the response body. The completable future is complete with true if the pushId is accepted, and with false if the pushId was rejected or cancelled. This method is intended to be called when onPushPromiseFrame(Http3ExchangeImpl, long, HttpHeaders), returns false, indicating that the push promise is being delegated to another request/response exchange. On completion of the future returned here, if the future is completed with true, the caller is expected to call PushGroup#acceptPushPromiseId(PushId) in order to notify the java.net.http.HttpResponse.PushPromiseHandler of the received pushId.

Parameters
pushId:long

the pushId

Returns:CompletableFuture<Boolean>

a completable future that will be completed when a pushId has been accepted by the exchange in charge of creating the response body

See Also
Http3Connection#whenPushAccepted(long)
jdk.internal.net.http back to summary

private final Record Http3PushManager.CancelledPushPromise

extends Record
implements PushPromise
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.Http3PushManager.PushPromise
Record Components
pushId:HttpResponse.PushPromiseHandler.PushId 

Represent a PushPromise that has been cancelled. No body will be delivered.

Field Summary

Modifier and TypeField and Description
private final HttpResponse.PushPromiseHandler.PushId
pushId

Record Component accessed by pushId().

Constructor Summary

AccessConstructor and Description
private

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 HttpResponse.PushPromiseHandler.PushId
pushId()

Record Component getter of pushId.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

pushIdback to summary
private final HttpResponse.PushPromiseHandler.PushId pushId

Record Component accessed by pushId().

Constructor Detail

CancelledPushPromiseback to summary
private CancelledPushPromise(HttpResponse.PushPromiseHandler.PushId pushId)

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.

pushIdback to summary
public HttpResponse.PushPromiseHandler.PushId pushId()

Record Component getter of pushId.

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.

jdk.internal.net.http back to summary

pack-priv final Enum Http3PushManager.CancelPushReason

extends Enum<Http3PushManager.CancelPushReason>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Http3PushManager.CancelPushReason
public static final Http3PushManager.CancelPushReason
public static final Http3PushManager.CancelPushReason

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Http3PushManager.CancelPushReason
public static Http3PushManager.CancelPushReason[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CANCEL_RECEIVEDback to summary
public static final Http3PushManager.CancelPushReason CANCEL_RECEIVED
NO_HANDLERback to summary
public static final Http3PushManager.CancelPushReason NO_HANDLER
PUSH_CANCELLEDback to summary
public static final Http3PushManager.CancelPushReason PUSH_CANCELLED

Constructor Detail

CancelPushReasonback to summary
private CancelPushReason()

Method Detail

valueOfback to summary
public static Http3PushManager.CancelPushReason valueOf(String name)
valuesback to summary
public static Http3PushManager.CancelPushReason[] values()
jdk.internal.net.http back to summary

private final Class Http3PushManager.PendingPushPromise<T>

extends Object
implements PushPromise
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.Http3PushManager.PushPromise
Type Parameters
<T>
the type of the body

Represents a PushPromise whose body has not been delivered yet.

Field Summary

Modifier and TypeField and Description
pack-priv final CompletableFuture<Boolean>
pack-priv Http3ExchangeImpl<T>
pack-priv HttpResponse.BodyHandler<T>
pack-priv HttpHeaders
pack-priv Http3PushPromiseStream<T>
pack-priv final long
pack-priv HttpRequestImpl
pack-priv CompletableFuture<HttpResponse<T>>
pack-priv QuicReceiverStream

Constructor Summary

AccessConstructor and Description
pack-priv
PendingPushPromise(Http3ExchangeImpl<T> exchange, long pushId, HttpHeaders promiseHeaders)

pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv String
pack-priv String
dbgTag(Http3PushPromiseStream<?> promiseStream)

public long
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

acceptedback to summary
pack-priv final CompletableFuture<Boolean> accepted
exchangeback to summary
pack-priv Http3ExchangeImpl<T> exchange
handlerback to summary
pack-priv HttpResponse.BodyHandler<T> handler
promiseHeadersback to summary
pack-priv HttpHeaders promiseHeaders
promiseStreamback to summary
pack-priv Http3PushPromiseStream<T> promiseStream
pushIdback to summary
pack-priv final long pushId
pushReqback to summary
pack-priv HttpRequestImpl pushReq
responseCFback to summary
pack-priv CompletableFuture<HttpResponse<T>> responseCF
streamback to summary
pack-priv QuicReceiverStream stream

Constructor Detail

PendingPushPromiseback to summary
pack-priv PendingPushPromise(Http3ExchangeImpl<T> exchange, long pushId, HttpHeaders promiseHeaders)
PendingPushPromiseback to summary
pack-priv PendingPushPromise(QuicReceiverStream stream, long pushId)

Method Detail

dbgTagback to summary
pack-priv String dbgTag(Http3ExchangeImpl<?> exchange)
dbgTagback to summary
pack-priv String dbgTag(Http3PushPromiseStream<?> promiseStream)
pushIdback to summary
public long pushId()
readyback to summary
public boolean ready()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

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

private final Record Http3PushManager.ProcessedPushPromise

extends Record
implements PushPromise
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.Http3PushManager.PushPromise
Record Components
pushId:HttpResponse.PushPromiseHandler.PushId 
promiseHeaders:HttpHeaders 

Represent a PushPromise whose body as already been delivered

Field Summary

Modifier and TypeField and Description
private final HttpHeaders
promiseHeaders

Record Component accessed by promiseHeaders().

private final HttpResponse.PushPromiseHandler.PushId
pushId

Record Component accessed by pushId().

Constructor Summary

AccessConstructor and Description
private

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 HttpHeaders
promiseHeaders()

Record Component getter of promiseHeaders.

public HttpResponse.PushPromiseHandler.PushId
pushId()

Record Component getter of pushId.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

promiseHeadersback to summary
private final HttpHeaders promiseHeaders

Record Component accessed by promiseHeaders().

pushIdback to summary
private final HttpResponse.PushPromiseHandler.PushId pushId

Record Component accessed by pushId().

Constructor Detail

ProcessedPushPromiseback to summary
private ProcessedPushPromise(HttpResponse.PushPromiseHandler.PushId pushId, HttpHeaders promiseHeaders)

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.

promiseHeadersback to summary
public HttpHeaders promiseHeaders()

Record Component getter of promiseHeaders.

pushIdback to summary
public HttpResponse.PushPromiseHandler.PushId pushId()

Record Component getter of pushId.

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.

jdk.internal.net.http back to summary

private sealed Interface Http3PushManager.PushPromise

permits Http3PushManager.PendingPushPromise<T>, ProcessedPushPromise, CancelledPushPromise
Known Direct Implementers
jdk.internal.net.http.Http3PushManager.ProcessedPushPromise, jdk.internal.net.http.Http3PushManager.CancelledPushPromise, jdk.internal.net.http.Http3PushManager.PendingPushPromise

A PushPromise can be a PendingPushPromise, until the push response is completely received, or a ProcessedPushPromise, which replace the PendingPushPromise after the response body has been delivered. If the PushPromise is cancelled before accepting it or receiving a body, CancelledPushPromise will be recorded and replace the PendingPushPromise.