Package com.unboundid.ldap.sdk
Class MaximumIdleDurationLDAPConnectionPoolHealthCheck
- java.lang.Object
-
- com.unboundid.ldap.sdk.LDAPConnectionPoolHealthCheck
-
- com.unboundid.ldap.sdk.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 theLDAPConnection.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 theLDAPConnectionPool.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., theGetEntryLDAPConnectionPoolHealthCheck
). 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 Summary
Constructors Constructor Description MaximumIdleDurationLDAPConnectionPoolHealthCheck(long maximumIdleDurationMillis)
Creates a new instance of this health check that will use the specified maximum idle duration.MaximumIdleDurationLDAPConnectionPoolHealthCheck(long maximumIdleDurationValue, java.util.concurrent.TimeUnit maximumIdleDurationTimeUnit)
Creates a new instance of this health check that will use the specified maximum idle duration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
ensureConnectionValidForContinuedUse(LDAPConnection connection)
Performs any desired processing to determine whether the provided connection is valid and should continue to be made available for processing operations.long
getIdleConnectionCount()
Retrieves the number of pooled connections that this health check has considered invalid because of their idle duration.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.void
toString(java.lang.StringBuilder buffer)
Appends a string representation of this LDAP connection pool health check to the provided buffer.-
Methods inherited from class com.unboundid.ldap.sdk.LDAPConnectionPoolHealthCheck
ensureConnectionValidAfterAuthentication, ensureConnectionValidAfterException, ensureConnectionValidForCheckout, ensureConnectionValidForRelease, ensureNewConnectionValid, performPoolMaintenance, toString
-
-
-
-
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 benull
.
-
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 anLDAPException
if a problem is detected.- Overrides:
ensureConnectionValidForContinuedUse
in classLDAPConnectionPoolHealthCheck
- 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 classLDAPConnectionPoolHealthCheck
- Parameters:
buffer
- The buffer to which the information should be appended.
-
-