Class MaximumIdleDurationLDAPConnectionPoolHealthCheck


  • @NotMutable
    @ThreadSafety(level=COMPLETELY_THREADSAFE)
    public final class MaximumIdleDurationLDAPConnectionPoolHealthCheck
    extends LDAPConnectionPoolHealthCheck
    This class provides an implementation of an LDAP connection pool health check that will cause the associated connection pool to consider a connection invalid after it has remained idle (as determined using the LDAPConnection.getLastCommunicationTime() method) for more than a specified length of time. This is primarily useful in cases where the associated directory servers (or some intermediate networking equipment) may terminate connections that have remained idle for too long.

    Note that in connection pools that may contain connections across multiple servers, you should probably use the LDAPConnectionPool.setMaxConnectionAgeMillis(long) method instead of this health check to ensure that connections are automatically refreshed after a specified duration, regardless of whether they have been idle. Setting a maximum connection age will help ensure that connections in the pool will return to a relatively balanced state after a failure has caused connections to migrate away from one or more of those servers.

    Also note that as an alternative to this health check, you may wish to consider a health check that actually attempts to communicate with the destination server over LDAP (e.g., the GetEntryLDAPConnectionPoolHealthCheck). Not only will those types of health checks do a better job of ensuring that the connection is still valid (and that the server to which it is established is responsive), but the communication that they perform will also prevent them from being considered idle.
    See Also:
    LDAPConnectionPool, LDAPConnectionPoolHealthCheck
    • Constructor Detail

      • MaximumIdleDurationLDAPConnectionPoolHealthCheck

        public MaximumIdleDurationLDAPConnectionPoolHealthCheck​(long maximumIdleDurationValue,
                                                                @NotNull
                                                                java.util.concurrent.TimeUnit maximumIdleDurationTimeUnit)
        Creates a new instance of this health check that will use the specified maximum idle duration.
        Parameters:
        maximumIdleDurationValue - The value that specifies the maximum length of time, in conjunction with the specified time unit, that connections will be allowed to remain idle before they will be replaced by the associated connection pool. This value must be greater than zero.
        maximumIdleDurationTimeUnit - The time unit to use when interpreting the provided maximum idle duration value. It must not be null.
      • MaximumIdleDurationLDAPConnectionPoolHealthCheck

        public MaximumIdleDurationLDAPConnectionPoolHealthCheck​(long maximumIdleDurationMillis)
        Creates a new instance of this health check that will use the specified maximum idle duration.
        Parameters:
        maximumIdleDurationMillis - The maximum length of time in milliseconds that connections will be allowed to remain idle before they will be replaced by the associated connection pool. This value must be greater than zero.
    • Method Detail

      • getMaximumIdleDurationMillis

        public long getMaximumIdleDurationMillis()
        Retrieves the maximum length of time in milliseconds that connections will be allowed to remain idle before they will be replaced by the associated connection pool.
        Returns:
        The maximum length of time in milliseconds that connections will be allowed to remain idle before they will be replaced by the associated connection pool.
      • getIdleConnectionCount

        public long getIdleConnectionCount()
        Retrieves the number of pooled connections that this health check has considered invalid because of their idle duration.
        Returns:
        The number of pooled connections that this health check has considered invalid because of their idle duration.
      • ensureConnectionValidForContinuedUse

        public void ensureConnectionValidForContinuedUse​(@NotNull
                                                         LDAPConnection connection)
                                                  throws LDAPException
        Performs any desired processing to determine whether the provided connection is valid and should continue to be made available for processing operations. This method will be periodically invoked by a background thread used to test availability of connections within the pool. This method should return normally if the connection is believed to be valid, or should throw an LDAPException if a problem is detected.
        Overrides:
        ensureConnectionValidForContinuedUse in class LDAPConnectionPoolHealthCheck
        Parameters:
        connection - The connection to be examined.
        Throws:
        LDAPException - If a problem is detected that suggests that the provided connection is not suitable for use.
      • toString

        public void toString​(@NotNull
                             java.lang.StringBuilder buffer)
        Appends a string representation of this LDAP connection pool health check to the provided buffer.
        Overrides:
        toString in class LDAPConnectionPoolHealthCheck
        Parameters:
        buffer - The buffer to which the information should be appended.