public final class RealConnectionPool
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.Runnable |
cleanupRunnable |
(package private) boolean |
cleanupRunning |
private java.util.Deque<RealConnection> |
connections |
private static java.util.concurrent.Executor |
executor
Background threads are used to cleanup expired connections.
|
private long |
keepAliveDurationNs |
private int |
maxIdleConnections
The maximum number of idle connections for each address.
|
(package private) RouteDatabase |
routeDatabase |
Constructor and Description |
---|
RealConnectionPool(int maxIdleConnections,
long keepAliveDuration,
java.util.concurrent.TimeUnit timeUnit) |
Modifier and Type | Method and Description |
---|---|
(package private) long |
cleanup(long now)
Performs maintenance on this pool, evicting the connection that has been idle the longest if
either it has exceeded the keep alive limit or the idle connections limit.
|
void |
connectFailed(Route failedRoute,
java.io.IOException failure)
Track a bad route in the route database.
|
(package private) boolean |
connectionBecameIdle(RealConnection connection)
Notify this pool that
connection has become idle. |
int |
connectionCount() |
void |
evictAll() |
int |
idleConnectionCount() |
private int |
pruneAndGetAllocationCount(RealConnection connection,
long now)
Prunes any leaked transmitters and then returns the number of remaining live transmitters on
connection . |
(package private) void |
put(RealConnection connection) |
(package private) boolean |
transmitterAcquirePooledConnection(Address address,
Transmitter transmitter,
java.util.List<Route> routes,
boolean requireMultiplexed)
Attempts to acquire a recycled connection to
address for transmitter . |
private static final java.util.concurrent.Executor executor
private final int maxIdleConnections
private final long keepAliveDurationNs
private final java.lang.Runnable cleanupRunnable
private final java.util.Deque<RealConnection> connections
final RouteDatabase routeDatabase
boolean cleanupRunning
public RealConnectionPool(int maxIdleConnections, long keepAliveDuration, java.util.concurrent.TimeUnit timeUnit)
public int idleConnectionCount()
public int connectionCount()
boolean transmitterAcquirePooledConnection(Address address, Transmitter transmitter, @Nullable java.util.List<Route> routes, boolean requireMultiplexed)
address
for transmitter
. Returns
true if a connection was acquired.
If routes
is non-null these are the resolved routes (ie. IP addresses) for the
connection. This is used to coalesce related domains to the same HTTP/2 connection, such as
square.com
and square.ca
.
void put(RealConnection connection)
boolean connectionBecameIdle(RealConnection connection)
connection
has become idle. Returns true if the connection has
been removed from the pool and should be closed.public void evictAll()
long cleanup(long now)
Returns the duration in nanos to sleep until the next scheduled call to this method. Returns -1 if no further cleanups are required.
private int pruneAndGetAllocationCount(RealConnection connection, long now)
connection
. Transmitters are leaked if the connection is tracking them but the
application code has abandoned them. Leak detection is imprecise and relies on garbage
collection.public void connectFailed(Route failedRoute, java.io.IOException failure)