public final class Transmitter
extends java.lang.Object
This class supports asynchronous canceling. This is intended to have the smallest blast radius possible. If an HTTP/2 stream is active, canceling will cancel that stream but not the other streams sharing its connection. But if the TLS handshake is still in progress then canceling may break the entire connection.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
Transmitter.TransmitterReference |
Modifier and Type | Field and Description |
---|---|
private Call |
call |
private java.lang.Object |
callStackTrace |
private boolean |
canceled |
private OkHttpClient |
client |
RealConnection |
connection |
private RealConnectionPool |
connectionPool |
private EventListener |
eventListener |
private Exchange |
exchange |
private ExchangeFinder |
exchangeFinder |
private boolean |
exchangeRequestDone |
private boolean |
exchangeResponseDone |
private boolean |
noMoreExchanges |
private Request |
request |
private okio.AsyncTimeout |
timeout |
private boolean |
timeoutEarlyExit |
Constructor and Description |
---|
Transmitter(OkHttpClient client,
Call call) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
acquireConnectionNoEvents(RealConnection connection) |
void |
callStart() |
void |
cancel()
Immediately closes the socket connection if it's currently held.
|
boolean |
canRetry() |
private Address |
createAddress(HttpUrl url) |
void |
exchangeDoneDueToException() |
(package private) java.io.IOException |
exchangeMessageDone(Exchange exchange,
boolean requestDone,
boolean responseDone,
java.io.IOException e)
Releases resources held with the request or response of
exchange . |
boolean |
hasExchange() |
boolean |
isCanceled() |
private java.io.IOException |
maybeReleaseConnection(java.io.IOException e,
boolean force)
Release the connection if it is no longer needed.
|
(package private) Exchange |
newExchange(Interceptor.Chain chain,
boolean doExtensiveHealthChecks)
Returns a new exchange to carry a new request and response.
|
java.io.IOException |
noMoreExchanges(java.io.IOException e) |
void |
prepareToConnect(Request request)
Prepare to create a stream to carry
request . |
(package private) java.net.Socket |
releaseConnectionNoEvents()
Remove the transmitter from the connection's list of allocations.
|
okio.Timeout |
timeout() |
void |
timeoutEarlyExit()
Stops applying the timeout before the call is entirely complete.
|
void |
timeoutEnter() |
private java.io.IOException |
timeoutExit(java.io.IOException cause) |
private final OkHttpClient client
private final RealConnectionPool connectionPool
private final Call call
private final EventListener eventListener
private final okio.AsyncTimeout timeout
@Nullable private java.lang.Object callStackTrace
private Request request
private ExchangeFinder exchangeFinder
public RealConnection connection
@Nullable private Exchange exchange
private boolean exchangeRequestDone
private boolean exchangeResponseDone
private boolean canceled
private boolean timeoutEarlyExit
private boolean noMoreExchanges
public Transmitter(OkHttpClient client, Call call)
public okio.Timeout timeout()
public void timeoutEnter()
public void timeoutEarlyExit()
@Nullable private java.io.IOException timeoutExit(@Nullable java.io.IOException cause)
public void callStart()
public void prepareToConnect(Request request)
request
. This prefers to use the existing
connection if it exists.Exchange newExchange(Interceptor.Chain chain, boolean doExtensiveHealthChecks)
void acquireConnectionNoEvents(RealConnection connection)
@Nullable java.net.Socket releaseConnectionNoEvents()
public void exchangeDoneDueToException()
@Nullable java.io.IOException exchangeMessageDone(Exchange exchange, boolean requestDone, boolean responseDone, @Nullable java.io.IOException e)
exchange
. This should be called
when the request completes normally or when it fails due to an exception, in which case e
should be non-null.
If the exchange was canceled or timed out, this will wrap e
in an exception that
provides that additional context. Otherwise e
is returned as-is.
@Nullable public java.io.IOException noMoreExchanges(@Nullable java.io.IOException e)
@Nullable private java.io.IOException maybeReleaseConnection(@Nullable java.io.IOException e, boolean force)
If the transmitter was canceled or timed out, this will wrap e
in an exception that
provides that additional context. Otherwise e
is returned as-is.
force
- true to release the connection even if more exchanges are expected for the call.public boolean canRetry()
public boolean hasExchange()
public void cancel()
This method is safe to be called concurrently, but provides limited guarantees. If a transport layer connection has been established (such as a HTTP/2 stream) that is terminated. Otherwise if a socket connection is being established, that is terminated.
public boolean isCanceled()