public final class Connection extends Object implements Closeable
Typically instances of this class are created, connected and exercised
automatically by the HTTP client. Applications may use this class to monitor
HTTP connections as members of a connection pool
.
Do not confuse this class with the misnamed HttpURLConnection
,
which isn't so much a connection as a single request/response exchange.
Constructor and Description |
---|
Connection(ConnectionPool pool,
Route route) |
Modifier and Type | Method and Description |
---|---|
boolean |
clearOwner()
Attempts to clears the owner of this connection.
|
void |
close() |
void |
closeIfOwnedBy(Object owner)
Closes this connection if it is currently owned by
owner . |
void |
connect(int connectTimeout,
int readTimeout,
TunnelRequest tunnelRequest) |
Handshake |
getHandshake() |
int |
getHttpMinorVersion()
Returns the minor HTTP version that should be used for future requests on
this connection.
|
long |
getIdleStartTimeNs()
Returns the time in ns when this connection became idle.
|
Object |
getOwner() |
Route |
getRoute()
Returns the route used by this connection.
|
Socket |
getSocket()
Returns the socket that this connection uses, or null if the connection
is not currently connected.
|
void |
incrementRecycleCount() |
boolean |
isAlive()
Returns true if this connection is alive.
|
boolean |
isConnected()
Returns true if
connect(int, int, com.squareup.okhttp.TunnelRequest) has been attempted on this connection. |
boolean |
isExpired(long keepAliveDurationNs)
Returns true if this connection has been idle for longer than
keepAliveDurationNs . |
boolean |
isIdle()
Returns true if this connection is idle.
|
boolean |
isReadable()
Returns true if we are confident that we can read data from this
connection.
|
boolean |
isSpdy()
Returns true if this is a SPDY connection.
|
Object |
newTransport(com.squareup.okhttp.internal.http.HttpEngine httpEngine)
Returns the transport appropriate for this connection.
|
int |
recycleCount()
Returns the number of times this connection has been returned to the
connection pool.
|
boolean |
requiresTunnel()
Returns true if the HTTP connection needs to tunnel one protocol over
another, such as when using HTTPS through an HTTP proxy.
|
void |
resetIdleStartTime() |
void |
setHttpMinorVersion(int httpMinorVersion) |
void |
setOwner(Object owner) |
void |
updateReadTimeout(int newTimeout) |
public Connection(ConnectionPool pool, Route route)
public Object getOwner()
public void setOwner(Object owner)
public boolean clearOwner()
closeIfOwnedBy(java.lang.Object)
.public void closeIfOwnedBy(Object owner) throws IOException
owner
. This also
strips the ownership of the connection so it cannot be pooled or reused.IOException
public void connect(int connectTimeout, int readTimeout, TunnelRequest tunnelRequest) throws IOException
IOException
public boolean isConnected()
connect(int, int, com.squareup.okhttp.TunnelRequest)
has been attempted on this connection.public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public Route getRoute()
public Socket getSocket()
public boolean isAlive()
public boolean isReadable()
public void resetIdleStartTime()
public boolean isIdle()
public boolean isExpired(long keepAliveDurationNs)
keepAliveDurationNs
.public long getIdleStartTimeNs()
public Handshake getHandshake()
public Object newTransport(com.squareup.okhttp.internal.http.HttpEngine httpEngine) throws IOException
IOException
public boolean isSpdy()
public int getHttpMinorVersion()
public void setHttpMinorVersion(int httpMinorVersion)
public boolean requiresTunnel()
public void updateReadTimeout(int newTimeout) throws IOException
IOException
public void incrementRecycleCount()
public int recycleCount()
Copyright © 2014. All Rights Reserved.