Class ValidatingConnectionPool

  • All Implemented Interfaces:, java.lang.AutoCloseable, ConnectionPool, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, 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.

    • Constructor Detail

      • ValidatingConnectionPool

        public ValidatingConnectionPool​(Destination destination,
                                        int maxConnections,
                                        Callback requester,
                                        Scheduler scheduler,
                                        long timeout)
    • Method Detail

      • getValidatingConnectionCount

        @ManagedAttribute(value="The number of validating connections",
        public int getValidatingConnectionCount()
      • remove

        public boolean remove​(Connection connection)
        Description copied from interface: ConnectionPool

        Removes the given connection from this ConnectionPool.

        Specified by:
        remove in interface ConnectionPool
        remove in class AbstractConnectionPool
        connection - the connection to remove
        true if the connection was removed from this ConnectionPool
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
        Description copied from interface: Dumpable
        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.
        Specified by:
        dump in interface Dumpable
        dump in class AbstractConnectionPool
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws: - if unable to write to Appendable