public class ValidatingConnectionPool extends DuplexConnectionPool
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.
AbstractLifeCycle.AbstractLifeCycleListener
ConnectionPool.Factory, ConnectionPool.Multiplexable
Dumpable.DumpableContainer
Container.InheritedListener, Container.Listener
LifeCycle.Listener
Constructor and Description |
---|
ValidatingConnectionPool(Destination destination,
int maxConnections,
Callback requester,
Scheduler scheduler,
long timeout) |
Modifier and Type | Method and Description |
---|---|
void |
dump(java.lang.Appendable out,
java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.
|
int |
getValidatingConnectionCount() |
boolean |
release(Connection connection)
Returns the given connection, previously obtained via
ConnectionPool.acquire() ,
back to this ConnectionPool. |
boolean |
remove(Connection connection)
Removes the given connection from this ConnectionPool.
|
java.lang.String |
toString() |
getMaxUsageCount, setMaxUsageCount
acquire, acquire, acquired, activate, close, deactivate, doStop, getActiveConnectionCount, getActiveConnections, getConnectionCount, getIdleConnectionCount, getIdleConnections, getMaxConnectionCount, getMaxDuration, getMaxMultiplex, getPendingConnectionCount, getPendingCount, idle, isActive, isClosed, isEmpty, isMaximizeConnections, onCreated, preCreateConnections, proceed, released, remove, removed, setMaxDuration, setMaximizeConnections, setMaxMultiplex, sweep, tryCreate
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
dump, dump, dumpContainer, dumpIterable, dumpMapEntries, dumpObject, dumpObjects, dumpSelf, named
isDumpable
public ValidatingConnectionPool(Destination destination, int maxConnections, Callback requester, Scheduler scheduler, long timeout)
@ManagedAttribute(value="The number of validating connections", readonly=true) public int getValidatingConnectionCount()
public boolean release(Connection connection)
ConnectionPool
Returns the given connection, previously obtained via ConnectionPool.acquire()
,
back to this ConnectionPool.
release
in interface ConnectionPool
release
in class AbstractConnectionPool
connection
- the connection to releasepublic boolean remove(Connection connection)
ConnectionPool
Removes the given connection from this ConnectionPool.
remove
in interface ConnectionPool
remove
in class AbstractConnectionPool
connection
- the connection to removepublic void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Dumpable
dump
in interface Dumpable
dump
in class AbstractConnectionPool
out
- The appendable to dump toindent
- The indent to apply after any new lines.java.io.IOException
- if unable to write to Appendablepublic java.lang.String toString()
toString
in class AbstractConnectionPool
Copyright © 1995–2021 Webtide. All rights reserved.