public final class StreamAllocation extends Object
Instances of this class act on behalf of the call, using one or more streams over one or more connections. This class has APIs to release each of the above resources:
noNewStreams()
prevents the connection from being used for new streams in the
future. Use this after a Connection: close
header, or when the connection may be
inconsistent.
streamFinished()
releases the active stream from this allocation.
Note that only one stream may be active at a given time, so it is necessary to call streamFinished()
before creating a subsequent stream with newStream()
.
release()
removes the call's hold on the connection. Note that this won't
immediately free the connection if there is a stream still lingering. That happens when a
call is complete but its response body has yet to be fully consumed.
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.
Constructor and Description |
---|
StreamAllocation(ConnectionPool connectionPool,
Address address) |
Modifier and Type | Method and Description |
---|---|
void |
acquire(RealConnection connection)
Use this allocation to hold
connection . |
void |
cancel() |
RealConnection |
connection() |
void |
connectionFailed()
Finish the current stream and prevent new streams from being created.
|
HttpStream |
newStream(int connectTimeout,
int readTimeout,
int writeTimeout,
boolean connectionRetryEnabled,
boolean doExtensiveHealthChecks) |
void |
noNewStreams()
Forbid new streams from being created on the connection that hosts this allocation.
|
boolean |
recover(IOException e,
okio.Sink requestBodyOut) |
boolean |
recover(RouteException e) |
void |
release() |
HttpStream |
stream() |
void |
streamFinished(HttpStream stream) |
String |
toString() |
public final Address address
public StreamAllocation(ConnectionPool connectionPool, Address address)
public HttpStream newStream(int connectTimeout, int readTimeout, int writeTimeout, boolean connectionRetryEnabled, boolean doExtensiveHealthChecks) throws RouteException, IOException
RouteException
IOException
public void streamFinished(HttpStream stream)
public HttpStream stream()
public RealConnection connection()
public void release()
public void noNewStreams()
public void cancel()
public void connectionFailed()
public void acquire(RealConnection connection)
connection
. Each call to this must be paired with a call to
release()
on the same connection.public boolean recover(RouteException e)
public boolean recover(IOException e, okio.Sink requestBodyOut)
Copyright © 2017. All rights reserved.