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

pack-priv Class Stream<T>

extends ExchangeImpl<T>
Class Inheritance
Known Direct Subclasses
jdk.internal.net.http.Stream.PushedStream
Imports
java.io.EOFException, .IOException, .UncheckedIOException, java.lang.invoke.MethodHandles, .VarHandle, java.net.ProtocolException, java.net.http.HttpResponse.BodyHandler, .HttpResponse.ResponseInfo, .HttpClient, .HttpHeaders, .HttpRequest, .HttpResponse, .HttpResponse.BodySubscriber, java.nio.ByteBuffer, java.util.ArrayList, .Collections, .List, java.util.concurrent.CompletableFuture, .ConcurrentLinkedDeque, .ConcurrentLinkedQueue, .Executor, .Flow, .Flow.Subscription, java.util.concurrent.atomic.AtomicInteger, .AtomicReference, java.util.concurrent.locks.Lock, .ReentrantLock, java.util.function.BiPredicate, jdk.internal.net.http.common.*, jdk.internal.net.http.frame.*, jdk.internal.net.http.hpack.DecodingCallback

Http/2 Stream handling. REQUESTS sendHeadersOnly() -- assembles HEADERS frame and puts on connection outbound Q sendRequest() -- sendHeadersOnly() + sendBody() sendBodyAsync() -- calls sendBody() in an executor thread. sendHeadersAsync() -- calls sendHeadersOnly() which does not block sendRequestAsync() -- calls sendRequest() in an executor thread RESPONSES Multiple responses can be received per request. Responses are queued up on a LinkedList of CF and the first one on the list is completed with the next response getResponseAsync() -- queries list of response CFs and returns first one if one exists. Otherwise, creates one and adds it to list and returns it. Completion is achieved through the incoming() upcall from connection reader thread. getResponse() -- calls getResponseAsync() and waits for CF to complete responseBodyAsync() -- calls responseBody() in an executor thread. incoming() -- entry point called from connection reader thread. Frames are either handled immediately without blocking or for data frames placed on the stream's inputQ which is consumed by the stream's reader thread. PushedStream subclass ===================== Sending side methods are not used because the request comes from a PUSH_PROMISE frame sent by the server. When a PUSH_PROMISE is received the PushedStream is created. PushedStream does not use responseCF list as there can be only one response. The CF is created when the object created and when the response HEADERS frame is received the object is completed.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
pack-priv class
pack-priv static class
pack-priv class
pack-priv class

Field Summary

Modifier and TypeField and Description
private volatile boolean
pack-priv static final ByteBuffer
pack-priv final Http2Connection
pack-priv final Logger
private volatile boolean
private static final VarHandle
private boolean
private volatile boolean
private final AtomicReference<Throwable>
private volatile boolean
pack-priv final ConcurrentLinkedQueue<Http2Frame>
private final Lock
private AtomicInteger
pack-priv volatile HttpResponse.BodySubscriber<T>
private volatile boolean
remotelyClosed

True if END_STREAM has been seen in a frame received on this stream.

pack-priv final HttpRequestImpl
pack-priv final CompletableFuture<Void>
pack-priv long
pack-priv final HttpHeaders
pack-priv final HttpRequest.BodyPublisher
private boolean
pack-priv volatile Stream<T>.RequestSubscriber
pack-priv volatile Response
pack-priv final List<CompletableFuture<Response>>
response_cfs

A List of responses relating to this stream.

pack-priv final Lock
pack-priv volatile CompletableFuture<T>
pack-priv volatile int
pack-priv final HttpHeadersBuilder
private boolean
pack-priv volatile HttpResponse.BodySubscriber<T>
pack-priv final Stream<T>.HeadersConsumer
pack-priv final SequentialScheduler
private final Lock
private final Lock
pack-priv volatile boolean
protected volatile int
streamid

This stream's identifier.

private volatile int
private final WindowUpdateSender
private volatile boolean
pack-priv final SubscriptionBase
private final WindowController
windowController

A reference to this Stream's connection Send Window controller.

Inherited from jdk.internal.net.http.ExchangeImpl:
exchange

Constructor Summary

AccessConstructor and Description
pack-priv
Stream(Http2Connection connection, Exchange<T> e, WindowController windowController)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
cancel()

Implements abstract jdk.internal.net.http.ExchangeImpl.cancel.

Cancels a request.

pack-priv void
cancel(IOException cause)

Implements abstract jdk.internal.net.http.ExchangeImpl.cancel.

Cancels a request with a cause.

pack-priv void
pack-priv void
cancelImpl(final Throwable e, final int resetFrameErrCode)

pack-priv String
private boolean
pack-priv void
pack-priv void
closeAsUnprocessed()

An unprocessed exchange is one that hasn't been processed by a peer.

pack-priv void
completed()

Implements abstract jdk.internal.net.http.ExchangeImpl.completed.

Called when the exchange is completed, so that cleanup actions may be performed - such as deregistering callbacks.

pack-priv void
completeResponse(Response resp)

Completes the first uncompleted CF on list, and removes it.

pack-priv void
completeResponseExceptionally(Throwable t)

same as above but for errors

pack-priv HttpConnection
connection()

Implements abstract jdk.internal.net.http.ExchangeImpl.connection.

Returns the HttpConnection instance to which this exchange is assigned.

pack-priv void
private boolean
pack-priv Stream<T>.Http2StreamResponseSubscriber<T>
pack-priv final String
pack-priv boolean
private void
private boolean
endStreamReceived()

Tells whether, or not, the END_STREAM Flag has been seen in any frame received on this stream.

pack-priv void
private HttpHeaders
pack-priv Throwable

Returns:

the cause for which this exchange was canceled, if available.
getCancelCause
()

Implements abstract jdk.internal.net.http.ExchangeImpl.getCancelCause.

Returns the cause for which this exchange was canceled, if available.

pack-priv DataFrame
private DataFrame
pack-priv HttpHeaders
pack-priv CompletableFuture<Response>
getResponseAsync(Executor executor)

Implements abstract jdk.internal.net.http.ExchangeImpl.getResponseAsync.

Gets the response headers.

pack-priv void
handleAltSvcFrame(int streamid, AltSvcFrame asf)

pack-priv void
handleReset(ResetFrame frame, Flow.Subscriber<?> subscriber)

protected void
private boolean
private OutgoingHeaders<Stream<T>>
headerFrame(long contentLength)

public CompletableFuture<Void>
ignoreBody()

Implements abstract jdk.internal.net.http.ExchangeImpl.ignoreBody.

Send a RESET frame to tell server to stop sending data on this stream

pack-priv void
incoming(Http2Frame frame)

Entry point from Http2Connection reader thread.

pack-priv void
pack-priv void
pack-priv void
private void
pack-priv void
pack-priv boolean

Returns:

true if this exchange was canceled.
isCanceled
()

Implements abstract jdk.internal.net.http.ExchangeImpl.isCanceled.

Returns true if this exchange was canceled.

pack-priv int

Returns:

the previous value of the stream state.
markStream
(int
the reason code as per HTTP/2 protocol
code
)

Records the first reason which was invoked when sending a ResetFrame to the server in the streamState, and return the previous value of the streamState.

private boolean
pack-priv void
pack-priv void
onProtocolError(final IOException cause)

Implements abstract jdk.internal.net.http.ExchangeImpl.onProtocolError.

Invoked whenever there is a (HTTP) protocol error when dealing with the response from the server.

pack-priv void
onProtocolError(final IOException cause, int code)

pack-priv void
pack-priv void
private void
pushDataFrame(int len, DataFrame df)

pack-priv CompletableFuture<T>
readBodyAsync(HttpResponse.BodyHandler<T> handler, boolean returnConnectionToPool, Executor executor)

Implements abstract jdk.internal.net.http.ExchangeImpl.readBodyAsync.

pack-priv CompletableFuture<T>
receiveData(HttpResponse.BodySubscriber<T> bodySubscriber, Executor executor)

private void
private void
receiveResetFrame(ResetFrame frame)

Handles a RESET frame.

private boolean
pack-priv boolean
registerStream(int id, boolean registerIfCancelled)

pack-priv void
released()

Implements abstract jdk.internal.net.http.ExchangeImpl.released.

Called when the exchange is released, so that cleanup actions may be performed - such as deregistering callbacks.

pack-priv void
pack-priv void
pack-priv DecodingCallback
private void
schedule()

Invoked either from incoming() -> {receiveDataFrame() or receiveResetFrame() } of after user subscription window has re-opened, from SubscriptionBase.request()

pack-priv CompletableFuture<ExchangeImpl<T>>
sendBodyAsync()

Implements abstract jdk.internal.net.http.ExchangeImpl.sendBodyAsync.

Sends a request body, after request headers have been sent.

pack-priv CompletableFuture<Void>
private void
pack-priv CompletableFuture<ExchangeImpl<T>>
pack-priv void
sendResetStreamFrame(final int resetFrameErrCode)

pack-priv void
setEndStreamReceived()

Sets endStreamReceived.

pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private boolean
Inherited from jdk.internal.net.http.ExchangeImpl:
cancelTimerOnResponseBodySubscriberTerminationclientexpectTimeoutRaisedgetgetExchangesetExpectTimeoutRaisedupgraded