A connection pool that validates connections before making them available for use.
Connections that have just been opened are not validated.
Connections that are released will
be validated.
Validation by reading from the EndPoint is not reliable, since the TCP FIN may arrive just after the validation read.
This class validates connections by putting them in a "quarantine" for a configurable timeout, where they cannot be used to send requests. When the timeout expires, the quarantined connection is made idle and therefore available to send requests.
The existing HttpClient mechanism to detect server closes will trigger and close quarantined connections, before they are made idle (and reusable) again.
There still is a small chance that the timeout expires, the connection is made idle and available again, it is used to send a request exactly when the server decides to close. This case is however unavoidable and may be mitigated by tuning the idle timeout of the servers to be larger than that of the client.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final Logger | |
| private final Map | |
| private final Scheduler | |
| private final long |
| Access | Constructor and Description |
|---|---|
| public | ValidatingConnectionPool(Destination destination, int maxConnections, Scheduler scheduler, long timeout)
|
| Modifier and Type | Method and Description |
|---|---|
| public void | dump(Appendable
The appendable to dump to out, String The indent to apply after any new lines. indent)Overrides org. Implements org. Dump this object (and children) into an Appendable using the provided indent after any new lines. |
| public int | |
| public boolean | release(Connection
the connection to release connection)Overrides org. Implements org. Returns the given connection, previously obtained via |
| public boolean | remove(Connection
the connection to remove connection)Overrides org. Implements org. Removes the given connection from this ConnectionPool. |
| public String | toString()
Overrides org. Returns a string representation of the object. |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| quarantine | back to summary |
|---|---|
| private final Map<Connection, ValidatingConnectionPool. | |
| scheduler | back to summary |
|---|---|
| private final Scheduler scheduler | |
| timeout | back to summary |
|---|---|
| private final long timeout | |
| ValidatingConnectionPool | back to summary |
|---|---|
| public ValidatingConnectionPool(Destination destination, int maxConnections, Scheduler scheduler, long timeout) | |
| dump | back to summary |
|---|---|
| public void dump(Appendable out, String indent) throws IOException Overrides org. Implements org. Doc from org. Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
| |
| getValidatingConnectionCount | back to summary |
|---|---|
public int getValidatingConnectionCount()
| |
| release | back to summary |
|---|---|
| public boolean release(Connection connection) Overrides org. Implements org. Doc from org. Returns the given connection, previously obtained via
| |
| remove | back to summary |
|---|---|
| public boolean remove(Connection connection) Overrides org. Implements org. Doc from org. Removes the given connection from this ConnectionPool.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| private final Connection | |
| private final long | |
| private final AtomicBoolean | |
| public Scheduler. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public void | |
| public String |
| connection | back to summary |
|---|---|
| private final Connection connection | |
| creationNanoTime | back to summary |
|---|---|
| private final long creationNanoTime | |
| done | back to summary |
|---|---|
| private final AtomicBoolean done | |
| task | back to summary |
|---|---|
| public Scheduler. | |
| Holder | back to summary |
|---|---|
| public Holder(Connection connection) | |
| cancel | back to summary |
|---|---|
| public boolean cancel() | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |