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

pack-priv Class MultiExchange<T>

extends Object
implements Cancelable
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.common.Cancelable
Imports
java.io.IOException, java.lang.ref.WeakReference, java.net.ConnectException, .ProtocolException, .ProtocolException, java.net.http.HttpClient.Version, .HttpConnectTimeoutException, .HttpHeaders, .StreamLimitException, .HttpClient, .HttpRequest, .HttpResponse, .HttpResponse.BodySubscriber, .HttpResponse.PushPromiseHandler, .HttpTimeoutException, java.time.Duration, java.util.List, .ListIterator, .Objects, .Optional, java.util.concurrent.CancellationException, .CompletableFuture, .CompletionStage, .Executor, .Flow, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, .AtomicReference, java.util.function.Function, jdk.internal.net.http.common.Cancelable, .Log, .Logger, .MinimalFuture, .ConnectionExpiredException, .Utils

Encapsulates multiple Exchanges belonging to one HttpRequestImpl. - manages filters - retries due to filters. - I/O errors and most other exceptions get returned directly to user Creates a new Exchange for each request/response interaction

Nested and Inner Type Summary

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

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicInteger
pack-priv volatile boolean
pack-priv final HttpClientImpl
private final MultiExchange.ConnectTimeoutTracker
pack-priv HttpRequestImpl
pack-priv static final Logger
pack-priv static final int
pack-priv Exchange<T>
pack-priv final HttpClientImpl.DelegatingExecutor
private final List<HeaderFilter>
pack-priv final long
private static final AtomicLong
pack-priv AtomicReference<CancellationException>
pack-priv static final int
pack-priv static final int
pack-priv volatile int
pack-priv Exchange<T>
pack-priv HttpRequestImpl
pack-priv volatile AuthenticationFilter.AuthInfo
proxyauth

Filter fields.

pack-priv final PushGroup<T>
private final HttpRequestImpl
pack-priv volatile HttpResponse<T>
pack-priv final HttpResponse.BodyHandler<T>
pack-priv volatile ResponseTimerEvent
private static final boolean
RETRY_ALWAYS

True if ALL ( even non-idempotent ) requests can be automatic retried.

pack-priv static final boolean
RETRY_CONNECT

True if ConnectException should cause a retry.

pack-priv volatile AuthenticationFilter.AuthInfo
serverauth

Filter fields.

private final AtomicInteger
private final HttpRequest

Constructor Summary

AccessConstructor and Description
pack-priv
MultiExchange(HttpRequest userRequest, HttpRequestImpl requestImpl, HttpClientImpl client, HttpResponse.BodyHandler<T> responseHandler, HttpResponse.PushPromiseHandler<T> pushPromiseHandler)

MultiExchange with one final response.

Method Summary

Modifier and TypeMethod and Description
private static boolean
public void
public boolean

Returns:

true if the exchange was cancelled, false otherwise.
cancel
(boolean
if true, and this exchange is not already cancelled, this method will attempt to interrupt and cancel the exchange. Otherwise, the exchange is allowed to proceed and this method does nothing.
mayInterruptIfRunning
)

Implements jdk.internal.net.http.common.Cancelable.cancel.

Used to relay a call from CompletableFuture#cancel(boolean) to this multi exchange for the purpose of cancelling the HTTP exchange.

pack-priv void
private MultiExchange.RetryContext

Returns:

a non-null RetryContext which contains the result of retry eligibility
checkRetryEligible
(final Throwable
the exception that caused the request to fail
requestFailureCause
,
final Exchange<?>
the Exchange
exchg
)

This method determines if a failed request can be retried.

pack-priv HttpClientImpl
private static boolean
private void
pack-priv synchronized Exchange<T>
private CompletableFuture<HttpResponse<T>>
private static boolean
isHttpMethodRetriable(HttpRequest request)

Returns true if the given request can be automatically retried.

private static boolean
isIdempotentRequest(HttpRequest request)

Returns true is given request has an idempotent method.

public <U> MinimalFuture<U>
public Optional<Duration>
pack-priv boolean
private void
public CompletableFuture<HttpResponse<T>>
private CompletableFuture<HttpResponse<T>>
private CompletableFuture<Response>
responseAsyncImpl(final boolean applyReqFilters)

private HttpRequestImpl
private static boolean
private CompletableFuture<Response>
private void
setExchange(Exchange<T> exchange)

private HttpResponse<T>
setNewResponse(HttpRequest request, Response r, T body, Exchange<T> exch)

pack-priv String
private HttpTimeoutException
pack-priv HttpClient.Version
private CompletableFuture<HttpResponse<T>>
private Throwable
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attemptsback to summary
pack-priv final AtomicInteger attempts
cancelledback to summary
pack-priv volatile boolean cancelled
clientback to summary
pack-priv final HttpClientImpl client
connectTimeoutback to summary
private final MultiExchange.ConnectTimeoutTracker connectTimeout
currentreqback to summary
pack-priv HttpRequestImpl currentreq
debugback to summary
pack-priv static final Logger debug
DEFAULT_MAX_ATTEMPTSback to summary
pack-priv static final int DEFAULT_MAX_ATTEMPTS
exchangeback to summary
pack-priv Exchange<T> exchange
executorback to summary
pack-priv final HttpClientImpl.DelegatingExecutor executor
filtersback to summary
private final List<HeaderFilter> filters
idback to summary
pack-priv final long id
IDSback to summary
private static final AtomicLong IDS
interruptedback to summary
pack-priv AtomicReference<CancellationException> interrupted
max_attemptsback to summary
pack-priv static final int max_attempts
max_stream_limit_attemptsback to summary
pack-priv static final int max_stream_limit_attempts
numberOfRedirectsback to summary
pack-priv volatile int numberOfRedirects
previousback to summary
pack-priv Exchange<T> previous
previousreqback to summary
pack-priv HttpRequestImpl previousreq
proxyauthback to summary
pack-priv volatile AuthenticationFilter.AuthInfo proxyauth

Filter fields. These are attached as required by filters and only used by the filter implementations. This could be generalised into Objects that are passed explicitly to the filters (one per MultiExchange object, and one per Exchange object possibly)

pushGroupback to summary
pack-priv final PushGroup<T> pushGroup
requestback to summary
private final HttpRequestImpl request
responseback to summary
pack-priv volatile HttpResponse<T> response
responseHandlerback to summary
pack-priv final HttpResponse.BodyHandler<T> responseHandler
responseTimerEventback to summary
pack-priv volatile ResponseTimerEvent responseTimerEvent
RETRY_ALWAYSback to summary
private static final boolean RETRY_ALWAYS

True if ALL ( even non-idempotent ) requests can be automatic retried.

RETRY_CONNECTback to summary
pack-priv static final boolean RETRY_CONNECT

True if ConnectException should cause a retry. Enabled by default

serverauthback to summary
pack-priv volatile AuthenticationFilter.AuthInfo serverauth

Filter fields. These are attached as required by filters and only used by the filter implementations. This could be generalised into Objects that are passed explicitly to the filters (one per MultiExchange object, and one per Exchange object possibly)

streamLimitRetriesback to summary
private final AtomicInteger streamLimitRetries
userRequestback to summary
private final HttpRequest userRequest

Constructor Detail

MultiExchangeback to summary
pack-priv MultiExchange(HttpRequest userRequest, HttpRequestImpl requestImpl, HttpClientImpl client, HttpResponse.BodyHandler<T> responseHandler, HttpResponse.PushPromiseHandler<T> pushPromiseHandler)

MultiExchange with one final response.

Method Detail

bodyNotPermittedback to summary
private static boolean bodyNotPermitted(Response r)
cancelback to summary
public void cancel(IOException cause)
cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements jdk.internal.net.http.common.Cancelable.cancel.

Used to relay a call from CompletableFuture#cancel(boolean) to this multi exchange for the purpose of cancelling the HTTP exchange.

Parameters
mayInterruptIfRunning:boolean

if true, and this exchange is not already cancelled, this method will attempt to interrupt and cancel the exchange. Otherwise, the exchange is allowed to proceed and this method does nothing.

Returns:boolean

true if the exchange was cancelled, false otherwise.

Annotations
@Override
cancelTimerback to summary
pack-priv void cancelTimer()
checkRetryEligibleback to summary
private MultiExchange.RetryContext checkRetryEligible(final Throwable requestFailureCause, final Exchange<?> exchg)

This method determines if a failed request can be retried. The returned RetryContext will contain the retry decision and the underlying cause (computed out of the given requestFailureCause) of the request failure.

Parameters
requestFailureCause:Throwable

the exception that caused the request to fail

exchg:Exchange<?>

the Exchange

Returns:MultiExchange.RetryContext

a non-null RetryContext which contains the result of retry eligibility

clientback to summary
pack-priv HttpClientImpl client()
disableRetryConnectback to summary
private static boolean disableRetryConnect()
ensureNoBodyback to summary
private void ensureNoBody(HttpHeaders headers) throws ProtocolException
getExchangeback to summary
pack-priv synchronized Exchange<T> getExchange()
handleNoBodyback to summary
private CompletableFuture<HttpResponse<T>> handleNoBody(Response r, Exchange<T> exch)
isHttpMethodRetriableback to summary
private static boolean isHttpMethodRetriable(HttpRequest request)

Returns true if the given request can be automatically retried.

isIdempotentRequestback to summary
private static boolean isIdempotentRequest(HttpRequest request)

Returns true is given request has an idempotent method.

newMinimalFutureback to summary
public <U> MinimalFuture<U> newMinimalFuture()
remainingConnectTimeoutback to summary
public Optional<Duration> remainingConnectTimeout()
requestCancelledback to summary
pack-priv boolean requestCancelled()
requestFiltersback to summary
private void requestFilters(HttpRequestImpl r) throws IOException
responseAsyncback to summary
public CompletableFuture<HttpResponse<T>> responseAsync(Executor executor)
responseAsync0back to summary
private CompletableFuture<HttpResponse<T>> responseAsync0(CompletableFuture<Void> start)
responseAsyncImplback to summary
private CompletableFuture<Response> responseAsyncImpl(final boolean applyReqFilters)
responseFiltersback to summary
private HttpRequestImpl responseFilters(Response response) throws IOException
retryPostValueback to summary
private static boolean retryPostValue()
retryRequestback to summary
private CompletableFuture<Response> retryRequest()
setExchangeback to summary
private void setExchange(Exchange<T> exchange)
setNewResponseback to summary
private HttpResponse<T> setNewResponse(HttpRequest request, Response r, T body, Exchange<T> exch)
streamLimitStateback to summary
pack-priv String streamLimitState()
toTimeoutExceptionback to summary
private HttpTimeoutException toTimeoutException(IOException ioe)
versionback to summary
pack-priv HttpClient.Version version()
whenCancelledback to summary
private CompletableFuture<HttpResponse<T>> whenCancelled(Throwable t)
wrapIfCancelledback to summary
private Throwable wrapIfCancelled(Throwable cause)
jdk.internal.net.http back to summary

pack-priv final Class MultiExchange.CancelableRef

extends Object
implements Cancelable
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.common.Cancelable

Field Summary

Modifier and TypeField and Description
private final WeakReference<Cancelable>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
cancel(boolean mayInterruptIfRunning)

Implements jdk.internal.net.http.common.Cancelable.cancel.

Attempts to cancel execution of a task.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cancelableRefback to summary
private final WeakReference<Cancelable> cancelableRef

Constructor Detail

CancelableRefback to summary
pack-priv CancelableRef(Cancelable cancelable)

Method Detail

cancelback to summary
public boolean cancel(boolean mayInterruptIfRunning)

Implements jdk.internal.net.http.common.Cancelable.cancel.

Doc from jdk.internal.net.http.common.Cancelable.cancel.

Attempts to cancel execution of a task. This attempt may not succeed if the task has already completed, has already been cancelled, or could not be cancelled for some other reason.

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

private final Class MultiExchange.ConnectTimeoutTracker

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final Duration
pack-priv final AtomicLong

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Duration
pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

maxback to summary
pack-priv final Duration max
startTimeback to summary
pack-priv final AtomicLong startTime

Constructor Detail

ConnectTimeoutTrackerback to summary
pack-priv ConnectTimeoutTracker(Duration connectTimeout)

Method Detail

getRemainingback to summary
pack-priv Duration getRemaining()
resetback to summary
pack-priv void reset()
jdk.internal.net.http back to summary

pack-priv Class MultiExchange.NullSubscription

extends Object
implements Subscription
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Flow.Subscription

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages.

public void
request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NullSubscriptionback to summary
pack-priv NullSubscription()

Method Detail

cancelback to summary
public void cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Doc from java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an onComplete or onError signal.

Annotations
@Override
requestback to summary
public void request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Doc from java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription. If n is less than or equal to zero, the Subscriber will receive an onError signal with an IllegalArgumentException argument. Otherwise, the Subscriber will receive up to n additional onNext invocations (or fewer if terminated).

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

private final Record MultiExchange.RetryContext

extends Record
Class Inheritance
Record Components
requestFailureCause:Throwable 
shouldRetry:boolean 
reqAttemptCounter:AtomicInteger 
shouldResetConnectTimer:boolean 

Field Summary

Modifier and TypeField and Description
private final AtomicInteger
reqAttemptCounter

Record Component accessed by reqAttemptCounter().

private final Throwable
requestFailureCause

Record Component accessed by requestFailureCause().

private final boolean
private final boolean
shouldRetry

Record Component accessed by shouldRetry().

Constructor Summary

AccessConstructor and Description
private
RetryContext(Throwable requestFailureCause, boolean shouldRetry, AtomicInteger reqAttemptCounter, boolean shouldResetConnectTimer)

Method Summary

Modifier and TypeMethod and Description
private static MultiExchange.RetryContext
doNotRetry(Throwable requestFailureCause)

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 AtomicInteger
reqAttemptCounter()

Record Component getter of reqAttemptCounter.

public Throwable
requestFailureCause()

Record Component getter of requestFailureCause.

public boolean
shouldResetConnectTimer()

Record Component getter of shouldResetConnectTimer.

public boolean
shouldRetry()

Record Component getter of shouldRetry.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

reqAttemptCounterback to summary
private final AtomicInteger reqAttemptCounter

Record Component accessed by reqAttemptCounter().

requestFailureCauseback to summary
private final Throwable requestFailureCause

Record Component accessed by requestFailureCause().

shouldResetConnectTimerback to summary
private final boolean shouldResetConnectTimer

Record Component accessed by shouldResetConnectTimer().

shouldRetryback to summary
private final boolean shouldRetry

Record Component accessed by shouldRetry().

Constructor Detail

RetryContextback to summary
private RetryContext(Throwable requestFailureCause, boolean shouldRetry, AtomicInteger reqAttemptCounter, boolean shouldResetConnectTimer)

Method Detail

doNotRetryback to summary
private static MultiExchange.RetryContext doNotRetry(Throwable requestFailureCause)
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.

reqAttemptCounterback to summary
public AtomicInteger reqAttemptCounter()

Record Component getter of reqAttemptCounter.

requestFailureCauseback to summary
public Throwable requestFailureCause()

Record Component getter of requestFailureCause.

shouldResetConnectTimerback to summary
public boolean shouldResetConnectTimer()

Record Component getter of shouldResetConnectTimer.

shouldRetryback to summary
public boolean shouldRetry()

Record Component getter of shouldRetry.

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.