Class ValidatingConnectionPool
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.client.AbstractConnectionPool
-
- org.eclipse.jetty.client.DuplexConnectionPool
-
- org.eclipse.jetty.client.ValidatingConnectionPool
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ConnectionPool
,org.eclipse.jetty.util.component.Container
,org.eclipse.jetty.util.component.Destroyable
,org.eclipse.jetty.util.component.Dumpable
,org.eclipse.jetty.util.component.Dumpable.DumpableContainer
,org.eclipse.jetty.util.component.LifeCycle
,org.eclipse.jetty.util.thread.Sweeper.Sweepable
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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.client.ConnectionPool
ConnectionPool.Factory, ConnectionPool.Multiplexable
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
-
Constructor Summary
Constructors Constructor Description ValidatingConnectionPool(Destination destination, int maxConnections, org.eclipse.jetty.util.Callback requester, org.eclipse.jetty.util.thread.Scheduler scheduler, long timeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
dump(java.lang.Appendable out, java.lang.String indent)
int
getValidatingConnectionCount()
boolean
release(Connection connection)
Returns the given connection, previously obtained viaConnectionPool.acquire()
, back to this ConnectionPool.boolean
remove(Connection connection)
Removes the given connection from this ConnectionPool.java.lang.String
toString()
-
Methods inherited from class org.eclipse.jetty.client.DuplexConnectionPool
getMaxUsageCount, setMaxUsageCount
-
Methods inherited from class org.eclipse.jetty.client.AbstractConnectionPool
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
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
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
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
-
-
-
Constructor Detail
-
ValidatingConnectionPool
public ValidatingConnectionPool(Destination destination, int maxConnections, org.eclipse.jetty.util.Callback requester, org.eclipse.jetty.util.thread.Scheduler scheduler, long timeout)
-
-
Method Detail
-
getValidatingConnectionCount
@ManagedAttribute(value="The number of validating connections", readonly=true) public int getValidatingConnectionCount()
-
release
public boolean release(Connection connection)
Description copied from interface:ConnectionPool
Returns the given connection, previously obtained via
ConnectionPool.acquire()
, back to this ConnectionPool.- Specified by:
release
in interfaceConnectionPool
- Overrides:
release
in classAbstractConnectionPool
- Parameters:
connection
- the connection to release- Returns:
- true if the connection has been released, false if the connection should be closed
-
remove
public boolean remove(Connection connection)
Description copied from interface:ConnectionPool
Removes the given connection from this ConnectionPool.
- Specified by:
remove
in interfaceConnectionPool
- Overrides:
remove
in classAbstractConnectionPool
- Parameters:
connection
- the connection to remove- Returns:
- true if the connection was removed from this ConnectionPool
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Overrides:
dump
in classAbstractConnectionPool
- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractConnectionPool
-
-