@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class LDAPConnectionPool extends AbstractConnectionPool
LDAPConnectionPool
class and the
LDAPConnection
class implement the LDAPInterface
interface.
This is a common interface that defines a number of common methods for
processing LDAP requests. This means that in many cases, an application can
use an object of type LDAPInterface
rather than
LDAPConnection
, which makes it possible to work with either a single
standalone connection or with a connection pool.
LDAPConnection
(for which an appropriate number of copies will be
created to fill out the pool) or using a ServerSet
to create
connections that may span multiple servers. For example:
// Create a new LDAP connection pool with ten connections established and // authenticated to the same server: LDAPConnection connection = new LDAPConnection(address, port); BindResult bindResult = connection.bind(bindDN, password); LDAPConnectionPool connectionPool = new LDAPConnectionPool(connection, 10); // Create a new LDAP connection pool with 10 connections spanning multiple // servers using a server set. RoundRobinServerSet serverSet = new RoundRobinServerSet(addresses, ports); SimpleBindRequest bindRequest = new SimpleBindRequest(bindDN, password); LDAPConnectionPool connectionPool = new LDAPConnectionPool(serverSet, bindRequest, 10);Note that in some cases, such as when using StartTLS, it may be necessary to perform some additional processing when a new connection is created for use in the connection pool. In this case, a
PostConnectProcessor
should
be provided to accomplish this. See the documentation for the
StartTLSPostConnectProcessor
class for an example that demonstrates
its use for creating a connection pool with connections secured using
StartTLS.
LDAPInterface
interface that allows a
connection pool to be treated like a single connection. For example, to
perform a search using a pooled connection:
SearchResult searchResult = connectionPool.search("dc=example,dc=com", SearchScope.SUB, "(uid=john.doe)");If an application needs to process multiple operations using a single connection, then it may be beneficial to obtain a connection from the pool to use for processing those operations and then return it back to the pool when it is no longer needed. This can be done using the
getConnection()
and releaseConnection(com.unboundid.ldap.sdk.LDAPConnection)
methods. If during
processing it is determined that the connection is no longer valid, then the
connection should be released back to the pool using the
releaseDefunctConnection(com.unboundid.ldap.sdk.LDAPConnection)
method, which will ensure that the
connection is closed and a new connection will be established to take its
place in the pool.
AbstractConnectionPool.processRequests(java.util.List<com.unboundid.ldap.sdk.LDAPRequest>, boolean)
method. This may be useful if
a fixed set of operations should be processed over the same connection and
none of the subsequent requests depend upon the results of the earlier
operations.
StartTLSPostConnectProcessor
).
getMaxWaitTimeMillis()
method, which has a default value of zero
to indicate that it should not wait at all) for an in-use connection to be
released back to the pool. If no connection is available after the specified
wait time (or there should not be any wait time), then the pool may
automatically create a new connection to use if
getCreateIfNecessary()
returns true
(which is the default).
If it is able to successfully create a connection, then it will be used. If
it cannot create a connection, or if getCreateIfNecessary()
returns
false
, then an LDAPException
will be thrown.
getCreateIfNecessary()
returns true
,
then there may temporarily be more active connections than the configured
maximum number of connections. This can be useful during periods of heavy
activity, because the pool will keep those connections established until the
number of unused connections exceeds the configured maximum. If you wish to
enforce a hard limit on the maximum number of connections so that there
cannot be more than the configured maximum in use at any time, then use the
setCreateIfNecessary(boolean)
method to indicate that the pool
should not automatically create connections when one is needed but none are
available, and you may also want to use the
setMaxWaitTimeMillis(long)
method to specify a maximum wait time to
allow the pool to wait for a connection to become available rather than
throwing an exception if no connections are immediately available.Constructor and Description |
---|
LDAPConnectionPool(LDAPConnection connection,
int numConnections)
Creates a new LDAP connection pool with up to the specified number of
connections, created as clones of the provided connection.
|
LDAPConnectionPool(LDAPConnection connection,
int initialConnections,
int maxConnections)
Creates a new LDAP connection pool with the specified number of
connections, created as clones of the provided connection.
|
LDAPConnectionPool(LDAPConnection connection,
int initialConnections,
int maxConnections,
int initialConnectThreads,
PostConnectProcessor postConnectProcessor,
boolean throwOnConnectFailure)
Creates a new LDAP connection pool with the specified number of
connections, created as clones of the provided connection.
|
LDAPConnectionPool(LDAPConnection connection,
int initialConnections,
int maxConnections,
int initialConnectThreads,
PostConnectProcessor postConnectProcessor,
boolean throwOnConnectFailure,
LDAPConnectionPoolHealthCheck healthCheck)
Creates a new LDAP connection pool with the specified number of
connections, created as clones of the provided connection.
|
LDAPConnectionPool(LDAPConnection connection,
int initialConnections,
int maxConnections,
PostConnectProcessor postConnectProcessor)
Creates a new LDAP connection pool with the specified number of
connections, created as clones of the provided connection.
|
LDAPConnectionPool(LDAPConnection connection,
int initialConnections,
int maxConnections,
PostConnectProcessor postConnectProcessor,
boolean throwOnConnectFailure)
Creates a new LDAP connection pool with the specified number of
connections, created as clones of the provided connection.
|
LDAPConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
int numConnections)
Creates a new LDAP connection pool with the specified number of
connections, created using the provided server set.
|
LDAPConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
int initialConnections,
int maxConnections)
Creates a new LDAP connection pool with the specified number of
connections, created using the provided server set.
|
LDAPConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
int initialConnections,
int maxConnections,
int initialConnectThreads,
PostConnectProcessor postConnectProcessor,
boolean throwOnConnectFailure)
Creates a new LDAP connection pool with the specified number of
connections, created using the provided server set.
|
LDAPConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
int initialConnections,
int maxConnections,
int initialConnectThreads,
PostConnectProcessor postConnectProcessor,
boolean throwOnConnectFailure,
LDAPConnectionPoolHealthCheck healthCheck)
Creates a new LDAP connection pool with the specified number of
connections, created using the provided server set.
|
LDAPConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
int initialConnections,
int maxConnections,
PostConnectProcessor postConnectProcessor)
Creates a new LDAP connection pool with the specified number of
connections, created using the provided server set.
|
LDAPConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
int initialConnections,
int maxConnections,
PostConnectProcessor postConnectProcessor,
boolean throwOnConnectFailure)
Creates a new LDAP connection pool with the specified number of
connections, created using the provided server set.
|
Modifier and Type | Method and Description |
---|---|
BindResult |
bindAndRevertAuthentication(BindRequest bindRequest)
Processes the provided bind request using a connection from this connection
pool, and then reverts that authentication by re-binding as the same user
used to authenticate new connections.
|
BindResult |
bindAndRevertAuthentication(java.lang.String bindDN,
java.lang.String password,
Control... controls)
Processes a simple bind using a connection from this connection pool, and
then reverts that authentication by re-binding as the same user used to
authenticate new connections.
|
boolean |
checkConnectionAgeOnRelease()
Indicates whether to check the age of a connection against the configured
maximum connection age whenever it is released to the pool.
|
void |
close()
Closes this connection pool.
|
void |
close(boolean unbind,
int numThreads)
Closes this connection pool, optionally using multiple threads to close the
connections in parallel.
|
void |
discardConnection(LDAPConnection connection)
Indicates that the provided connection should be removed from the pool,
and that no new connection should be created to take its place.
|
protected void |
doHealthCheck()
Performs a health check against all connections currently available in this
connection pool.
|
protected void |
finalize()
Closes this connection pool in the event that it becomes unreferenced.
|
LDAPConnection |
getConnection()
Retrieves an LDAP connection from the pool.
|
LDAPConnection |
getConnection(java.lang.String host,
int port)
Attempts to retrieve a connection from the pool that is established to the
specified server.
|
java.lang.String |
getConnectionPoolName()
Retrieves the user-friendly name that has been assigned to this connection
pool.
|
LDAPConnectionPoolStatistics |
getConnectionPoolStatistics()
Retrieves the set of statistics maintained for this LDAP connection pool.
|
boolean |
getCreateIfNecessary()
Indicates whether the connection pool should create a new connection if one
is requested when there are none available.
|
int |
getCurrentAvailableConnections()
Retrieves the number of connections that are currently available for use in
this connection pool, if applicable.
|
LDAPConnectionPoolHealthCheck |
getHealthCheck()
Retrieves the health check implementation for this connection pool.
|
long |
getHealthCheckIntervalMillis()
Retrieves the length of time in milliseconds between periodic background
health checks against the available connections in this pool.
|
long |
getMaxConnectionAgeMillis()
Retrieves the maximum length of time in milliseconds that a connection in
this pool may be established before it is closed and replaced with another
connection.
|
java.lang.Long |
getMaxDefunctReplacementConnectionAgeMillis()
Retrieves the maximum connection age that should be used for connections
that were created in order to replace defunct connections.
|
int |
getMaximumAvailableConnections()
Retrieves the maximum number of connections to be maintained in this
connection pool, which is the maximum number of available connections that
should be available at any time, if applicable.
|
long |
getMaxWaitTimeMillis()
Retrieves the maximum length of time in milliseconds to wait for a
connection to become available when trying to obtain a connection from the
pool.
|
long |
getMinDisconnectIntervalMillis()
Retrieves the minimum length of time in milliseconds that should pass
between connections closed because they have been established for longer
than the maximum connection age.
|
int |
getMinimumAvailableConnectionGoal()
Retrieves the goal for the minimum number of available connections that the
pool should try to maintain for immediate use.
|
java.util.Set<OperationType> |
getOperationTypesToRetryDueToInvalidConnections()
Retrieves the set of operation types for which operations should be
retried if the initial attempt fails in a manner that indicates that the
connection used to process the request may no longer be valid.
|
ServerSet |
getServerSet()
Retrieves the server set that should be used to establish new connections
for use in this connection pool.
|
LDAPConnectionPoolHealthCheckResult |
invokeHealthCheck(LDAPConnectionPoolHealthCheck healthCheck,
boolean checkForExpiration)
Invokes a synchronous one-time health-check against the connections in this
pool that are not currently in use.
|
LDAPConnectionPoolHealthCheckResult |
invokeHealthCheck(LDAPConnectionPoolHealthCheck healthCheck,
boolean checkForExpiration,
boolean checkMinConnectionGoal)
Invokes a synchronous one-time health-check against the connections in this
pool that are not currently in use.
|
boolean |
isClosed()
Indicates whether this connection pool has been closed.
|
void |
releaseAndReAuthenticateConnection(LDAPConnection connection)
Performs a bind on the provided connection before releasing it back to the
pool, so that it will be authenticated as the same user as
newly-established connections.
|
void |
releaseConnection(LDAPConnection connection)
Releases the provided connection back to this pool.
|
void |
releaseDefunctConnection(LDAPConnection connection)
Indicates that the provided connection is no longer in use, but is also no
longer fit for use.
|
LDAPConnection |
replaceDefunctConnection(LDAPConnection connection)
Releases the provided connection as defunct and creates a new connection to
replace it, if possible, optionally connected to a different directory
server instance than the instance with which the original connection was
established.
|
void |
setBindRequest(BindRequest bindRequest)
Specifies the bind request that will be used to authenticate subsequent new
connections that are established by this connection pool.
|
void |
setCheckConnectionAgeOnRelease(boolean checkConnectionAgeOnRelease)
Specifies whether to check the age of a connection against the configured
maximum connection age whenever it is released to the pool.
|
void |
setConnectionPoolName(java.lang.String connectionPoolName)
Specifies the user-friendly name that should be used for this connection
pool.
|
void |
setCreateIfNecessary(boolean createIfNecessary)
Specifies whether the connection pool should create a new connection if one
is requested when there are none available.
|
void |
setHealthCheck(LDAPConnectionPoolHealthCheck healthCheck)
Sets the health check implementation for this connection pool.
|
void |
setHealthCheckIntervalMillis(long healthCheckInterval)
Specifies the length of time in milliseconds between periodic background
health checks against the available connections in this pool.
|
void |
setMaxConnectionAgeMillis(long maxConnectionAge)
Specifies the maximum length of time in milliseconds that a connection in
this pool may be established before it should be closed and replaced with
another connection.
|
void |
setMaxDefunctReplacementConnectionAgeMillis(java.lang.Long maxDefunctReplacementConnectionAge)
Specifies the maximum connection age that should be used for connections
that were created in order to replace defunct connections.
|
void |
setMaxWaitTimeMillis(long maxWaitTime)
Specifies the maximum length of time in milliseconds to wait for a
connection to become available when trying to obtain a connection from the
pool.
|
void |
setMinDisconnectIntervalMillis(long minDisconnectInterval)
Specifies the minimum length of time in milliseconds that should pass
between connections closed because they have been established for longer
than the maximum connection age.
|
void |
setMinimumAvailableConnectionGoal(int goal)
Specifies the goal for the minimum number of available connections that the
pool should try to maintain for immediate use.
|
void |
setRetryFailedOperationsDueToInvalidConnections(java.util.Set<OperationType> operationTypes)
Specifies the types of operations that should be retried on a newly-created
connection if the initial attempt fails in a manner that indicates that
the connection used to process the request may no longer be valid.
|
void |
setServerSet(ServerSet serverSet)
Specifies the server set that should be used to establish new connections
for use in this connection pool.
|
void |
setTrySynchronousReadDuringHealthCheck(boolean trySynchronousReadDuringHealthCheck)
Specifies whether health check processing for connections operating in
synchronous mode should include attempting to perform a read from each
connection with a very short timeout.
|
void |
shrinkPool(int connectionsToRetain)
Attempts to reduce the number of connections available for use in the pool.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this connection pool to the provided
buffer.
|
boolean |
trySynchronousReadDuringHealthCheck()
Indicates whether health check processing for connections operating in
synchronous mode should include attempting to perform a read from each
connection with a very short timeout.
|
add, add, add, add, add, add, bind, bind, compare, compare, compare, delete, delete, delete, getEntry, getEntry, getRootDSE, getSchema, getSchema, modify, modify, modify, modify, modify, modify, modifyDN, modifyDN, modifyDN, modifyDN, processExtendedOperation, processExtendedOperation, processExtendedOperation, processRequests, processRequestsAsync, releaseConnectionAfterException, retryFailedOperationsDueToInvalidConnections, search, search, search, search, search, search, search, search, search, search, searchForEntry, searchForEntry, searchForEntry, searchForEntry, searchForEntry, searchForEntry, setRetryFailedOperationsDueToInvalidConnections, toString
public LDAPConnectionPool(@NotNull LDAPConnection connection, int numConnections) throws LDAPException
connection
- The connection to use to provide the template for
the other connections to be created. This
connection will be included in the pool. It must
not be null
, and it must be established to
the target server. It does not necessarily need to
be authenticated if all connections in the pool are
to be unauthenticated.numConnections
- The total number of connections that should be
created in the pool. It must be greater than or
equal to one.LDAPException
- If the provided connection cannot be used to
initialize the pool, or if a problem occurs while
attempting to establish any of the connections. If
this is thrown, then all connections associated
with the pool (including the one provided as an
argument) will be closed.public LDAPConnectionPool(@NotNull LDAPConnection connection, int initialConnections, int maxConnections) throws LDAPException
connection
- The connection to use to provide the template
for the other connections to be created. This
connection will be included in the pool. It
must not be null
, and it must be
established to the target server. It does not
necessarily need to be authenticated if all
connections in the pool are to be
unauthenticated.initialConnections
- The number of connections to initially
establish when the pool is created. It must be
greater than or equal to one.maxConnections
- The maximum number of connections that should
be maintained in the pool. It must be greater
than or equal to the initial number of
connections. See the "Pool Connection
Management" section of the class-level
documentation for an explanation of how the
pool treats the maximum number of connections.LDAPException
- If the provided connection cannot be used to
initialize the pool, or if a problem occurs while
attempting to establish any of the connections. If
this is thrown, then all connections associated
with the pool (including the one provided as an
argument) will be closed.public LDAPConnectionPool(@NotNull LDAPConnection connection, int initialConnections, int maxConnections, @Nullable PostConnectProcessor postConnectProcessor) throws LDAPException
connection
- The connection to use to provide the template
for the other connections to be created.
This connection will be included in the pool.
It must not be null
, and it must be
established to the target server. It does
not necessarily need to be authenticated if
all connections in the pool are to be
unauthenticated.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to one.maxConnections
- The maximum number of connections that should
be maintained in the pool. It must be
greater than or equal to the initial number
of connections. See the "Pool Connection
Management" section of the class-level
documentation for an explanation of how the
pool treats the maximum number of
connections.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that this
processing will not be invoked on the
provided connection that will be used as the
first connection in the pool.LDAPException
- If the provided connection cannot be used to
initialize the pool, or if a problem occurs while
attempting to establish any of the connections. If
this is thrown, then all connections associated
with the pool (including the one provided as an
argument) will be closed.public LDAPConnectionPool(@NotNull LDAPConnection connection, int initialConnections, int maxConnections, @Nullable PostConnectProcessor postConnectProcessor, boolean throwOnConnectFailure) throws LDAPException
connection
- The connection to use to provide the
template for the other connections to be
created. This connection will be included
in the pool. It must not be null
,
and it must be established to the target
server. It does not necessarily need to be
authenticated if all connections in the pool
are to be unauthenticated.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to one.maxConnections
- The maximum number of connections that
should be maintained in the pool. It must
be greater than or equal to the initial
number of connections. See the "Pool
Connection Management" section of the
class-level documentation for an explanation
of how the pool treats the maximum number of
connections.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that
this processing will not be invoked on the
provided connection that will be used as the
first connection in the pool.throwOnConnectFailure
- If an exception should be thrown if a
problem is encountered while attempting to
create the specified initial number of
connections. If true
, then the
attempt to create the pool will fail.if any
connection cannot be established. If
false
, then the pool will be created
but may have fewer than the initial number
of connections (or possibly no connections).LDAPException
- If the provided connection cannot be used to
initialize the pool, or if a problem occurs while
attempting to establish any of the connections. If
this is thrown, then all connections associated
with the pool (including the one provided as an
argument) will be closed.public LDAPConnectionPool(@NotNull LDAPConnection connection, int initialConnections, int maxConnections, int initialConnectThreads, @Nullable PostConnectProcessor postConnectProcessor, boolean throwOnConnectFailure) throws LDAPException
connection
- The connection to use to provide the
template for the other connections to be
created. This connection will be included
in the pool. It must not be null
,
and it must be established to the target
server. It does not necessarily need to be
authenticated if all connections in the pool
are to be unauthenticated.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to one.maxConnections
- The maximum number of connections that
should be maintained in the pool. It must
be greater than or equal to the initial
number of connections. See the "Pool
Connection Management" section of the
class-level documentation for an
explanation of how the pool treats the
maximum number of connections.initialConnectThreads
- The number of concurrent threads to use to
establish the initial set of connections.
A value greater than one indicates that the
attempt to establish connections should be
parallelized.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that
this processing will not be invoked on the
provided connection that will be used as the
first connection in the pool.throwOnConnectFailure
- If an exception should be thrown if a
problem is encountered while attempting to
create the specified initial number of
connections. If true
, then the
attempt to create the pool will fail.if any
connection cannot be established. If
false
, then the pool will be created
but may have fewer than the initial number
of connections (or possibly no connections).LDAPException
- If the provided connection cannot be used to
initialize the pool, or if a problem occurs while
attempting to establish any of the connections. If
this is thrown, then all connections associated
with the pool (including the one provided as an
argument) will be closed.public LDAPConnectionPool(@NotNull LDAPConnection connection, int initialConnections, int maxConnections, int initialConnectThreads, @Nullable PostConnectProcessor postConnectProcessor, boolean throwOnConnectFailure, @Nullable LDAPConnectionPoolHealthCheck healthCheck) throws LDAPException
connection
- The connection to use to provide the
template for the other connections to be
created. This connection will be included
in the pool. It must not be null
,
and it must be established to the target
server. It does not necessarily need to be
authenticated if all connections in the pool
are to be unauthenticated.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to one.maxConnections
- The maximum number of connections that
should be maintained in the pool. It must
be greater than or equal to the initial
number of connections. See the "Pool
Connection Management" section of the
class-level documentation for an explanation
of how the pool treats the maximum number of
connections.initialConnectThreads
- The number of concurrent threads to use to
establish the initial set of connections.
A value greater than one indicates that the
attempt to establish connections should be
parallelized.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that
this processing will not be invoked on the
provided connection that will be used as the
first connection in the pool.throwOnConnectFailure
- If an exception should be thrown if a
problem is encountered while attempting to
create the specified initial number of
connections. If true
, then the
attempt to create the pool will fail.if any
connection cannot be established. If
false
, then the pool will be created
but may have fewer than the initial number
of connections (or possibly no connections).healthCheck
- The health check that should be used for
connections in this pool. It may be
null
if the default health check
should be used.LDAPException
- If the provided connection cannot be used to
initialize the pool, or if a problem occurs while
attempting to establish any of the connections. If
this is thrown, then all connections associated
with the pool (including the one provided as an
argument) will be closed.public LDAPConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, int numConnections) throws LDAPException
serverSet
- The server set to use to create the connections.
It is acceptable for the server set to create the
connections across multiple servers.bindRequest
- The bind request to use to authenticate the
connections that are established. It may be
null
if no authentication should be
performed on the connections. Note that if the
server set is configured to perform
authentication, this bind request should be the
same bind request used by the server set. This is
important because even though the server set may
be used to perform the initial authentication on a
newly established connection, this connection
pool may still need to re-authenticate the
connection.numConnections
- The total number of connections that should be
created in the pool. It must be greater than or
equal to one.LDAPException
- If a problem occurs while attempting to establish
any of the connections. If this is thrown, then
all connections associated with the pool will be
closed.public LDAPConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, int initialConnections, int maxConnections) throws LDAPException
serverSet
- The server set to use to create the
connections. It is acceptable for the server
set to create the connections across multiple
servers.bindRequest
- The bind request to use to authenticate the
connections that are established. It may be
null
if no authentication should be
performed on the connections. Note that if the
server set is configured to perform
authentication, this bind request should be the
same bind request used by the server set.
This is important because even though the
server set may be used to perform the initial
authentication on a newly established
connection, this connection pool may still
need to re-authenticate the connection.initialConnections
- The number of connections to initially
establish when the pool is created. It must be
greater than or equal to zero.maxConnections
- The maximum number of connections that should
be maintained in the pool. It must be greater
than or equal to the initial number of
connections, and must not be zero. See the
"Pool Connection Management" section of the
class-level documentation for an explanation of
how the pool treats the maximum number of
connections.LDAPException
- If a problem occurs while attempting to establish
any of the connections. If this is thrown, then
all connections associated with the pool will be
closed.public LDAPConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, int initialConnections, int maxConnections, @Nullable PostConnectProcessor postConnectProcessor) throws LDAPException
serverSet
- The server set to use to create the
connections. It is acceptable for the server
set to create the connections across multiple
servers.bindRequest
- The bind request to use to authenticate the
connections that are established. It may be
null
if no authentication should be
performed on the connections. Note that if
the server set is configured to perform
authentication, this bind request should be
the same bind request used by the server set.
This is important because even though the
server set may be used to perform the initial
authentication on a newly established
connection, this connection pool may still
need to re-authenticate the connection.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to zero.maxConnections
- The maximum number of connections that should
be maintained in the pool. It must be
greater than or equal to the initial number
of connections, and must not be zero. See
the "Pool Connection Management" section of
the class-level documentation for an
explanation of how the pool treats the
maximum number of connections.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that if
the server set is configured with a
non-null
post-connect processor, then
the post-connect processor provided to the
pool must be null
.LDAPException
- If a problem occurs while attempting to establish
any of the connections. If this is thrown, then
all connections associated with the pool will be
closed.public LDAPConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, int initialConnections, int maxConnections, @Nullable PostConnectProcessor postConnectProcessor, boolean throwOnConnectFailure) throws LDAPException
serverSet
- The server set to use to create the
connections. It is acceptable for the
server set to create the connections across
multiple servers.bindRequest
- The bind request to use to authenticate the
connections that are established. It may be
null
if no authentication should be
performed on the connections. Note that if
the server set is configured to perform
authentication, this bind request should be
the same bind request used by the server
set. This is important because even
though the server set may be used to
perform the initial authentication on a
newly established connection, this
connection pool may still need to
re-authenticate the connection.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to zero.maxConnections
- The maximum number of connections that
should be maintained in the pool. It must
be greater than or equal to the initial
number of connections, and must not be zero.
See the "Pool Connection Management" section
of the class-level documentation for an
explanation of how the pool treats the
maximum number of connections.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that if
the server set is configured with a
non-null
post-connect processor,
then the post-connect processor provided
to the pool must be null
.throwOnConnectFailure
- If an exception should be thrown if a
problem is encountered while attempting to
create the specified initial number of
connections. If true
, then the
attempt to create the pool will fail.if any
connection cannot be established. If
false
, then the pool will be created
but may have fewer than the initial number
of connections (or possibly no connections).LDAPException
- If a problem occurs while attempting to establish
any of the connections and
throwOnConnectFailure
is true. If this is
thrown, then all connections associated with the
pool will be closed.public LDAPConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, int initialConnections, int maxConnections, int initialConnectThreads, @Nullable PostConnectProcessor postConnectProcessor, boolean throwOnConnectFailure) throws LDAPException
serverSet
- The server set to use to create the
connections. It is acceptable for the
server set to create the connections across
multiple servers.bindRequest
- The bind request to use to authenticate the
connections that are established. It may be
null
if no authentication should be
performed on the connections. Note that if
the server set is configured to perform
authentication, this bind request should be
the same bind request used by the server
set. This is important because even
though the server set may be used to
perform the initial authentication on a
newly established connection, this
connection pool may still need to
re-authenticate the connection.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to zero.maxConnections
- The maximum number of connections that
should be maintained in the pool. It must
be greater than or equal to the initial
number of connections, and must not be zero.
See the "Pool Connection Management" section
of the class-level documentation for an
explanation of how the pool treats the
maximum number of connections.initialConnectThreads
- The number of concurrent threads to use to
establish the initial set of connections.
A value greater than one indicates that the
attempt to establish connections should be
parallelized.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that if
the server set is configured with a
non-null
post-connect processor,
then the post-connect processor provided
to the pool must be null
.throwOnConnectFailure
- If an exception should be thrown if a
problem is encountered while attempting to
create the specified initial number of
connections. If true
, then the
attempt to create the pool will fail.if any
connection cannot be established. If
false
, then the pool will be created
but may have fewer than the initial number
of connections (or possibly no connections).LDAPException
- If a problem occurs while attempting to establish
any of the connections and
throwOnConnectFailure
is true. If this is
thrown, then all connections associated with the
pool will be closed.public LDAPConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, int initialConnections, int maxConnections, int initialConnectThreads, @Nullable PostConnectProcessor postConnectProcessor, boolean throwOnConnectFailure, @Nullable LDAPConnectionPoolHealthCheck healthCheck) throws LDAPException
serverSet
- The server set to use to create the
connections. It is acceptable for the
server set to create the connections across
multiple servers.bindRequest
- The bind request to use to authenticate the
connections that are established. It may be
null
if no authentication should be
performed on the connections. Note that if
the server set is configured to perform
authentication, this bind request should be
the same bind request used by the server
set. This is important because even
though the server set may be used to
perform the initial authentication on a
newly established connection, this
connection pool may still need to
re-authenticate the connection.initialConnections
- The number of connections to initially
establish when the pool is created. It must
be greater than or equal to zero.maxConnections
- The maximum number of connections that
should be maintained in the pool. It must
be greater than or equal to the initial
number of connections, and must not be zero.
See the "Pool Connection Management" section
of the class-level documentation for an
explanation of how the pool treats the
maximum number of connections.initialConnectThreads
- The number of concurrent threads to use to
establish the initial set of connections.
A value greater than one indicates that the
attempt to establish connections should be
parallelized.postConnectProcessor
- A processor that should be used to perform
any post-connect processing for connections
in this pool. It may be null
if no
special processing is needed. Note that if
the server set is configured with a
non-null
post-connect processor,
then the post-connect processor provided
to the pool must be null
.throwOnConnectFailure
- If an exception should be thrown if a
problem is encountered while attempting to
create the specified initial number of
connections. If true
, then the
attempt to create the pool will fail if any
connection cannot be established. If
false
, then the pool will be created
but may have fewer than the initial number
of connections (or possibly no connections).healthCheck
- The health check that should be used for
connections in this pool. It may be
null
if the default health check
should be used.LDAPException
- If a problem occurs while attempting to establish
any of the connections and
throwOnConnectFailure
is true. If this is
thrown, then all connections associated with the
pool will be closed.public void close()
close
in interface FullLDAPInterface
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class AbstractConnectionPool
public void close(boolean unbind, int numThreads)
close
in class AbstractConnectionPool
unbind
- Indicates whether to try to send an unbind request to
the server before closing the connection.numThreads
- The number of threads to use when closing the
connections.public boolean isClosed()
isClosed
in class AbstractConnectionPool
true
if this connection pool has been closed, or
false
if not.@NotNull public BindResult bindAndRevertAuthentication(@Nullable java.lang.String bindDN, @Nullable java.lang.String password, @Nullable Control... controls) throws LDAPException
bindDN
- The bind DN for the simple bind request.password
- The password for the simple bind request.controls
- The optional set of controls for the simple bind request.LDAPException
- If the server rejects the bind request, or if a
problem occurs while sending the request or reading
the response.@NotNull public BindResult bindAndRevertAuthentication(@NotNull BindRequest bindRequest) throws LDAPException
bindRequest
- The bind request to be processed. It must not be
null
.LDAPException
- If the server rejects the bind request, or if a
problem occurs while sending the request or reading
the response.@NotNull public LDAPConnection getConnection() throws LDAPException
getConnection
in class AbstractConnectionPool
LDAPException
- If no connection is available, or a problem occurs
while creating a new connection to return.@Nullable public LDAPConnection getConnection(@NotNull java.lang.String host, int port)
host
- The address of the server to which the desired connection
should be established. This must not be null
, and
this must exactly match the address provided for the initial
connection or the ServerSet
used to create the pool.port
- The port of the server to which the desired connection should
be established.null
if there are no available connections established to
the specified server.public void releaseConnection(@NotNull LDAPConnection connection)
releaseConnection
in class AbstractConnectionPool
connection
- The connection to be released back to the pool.public void discardConnection(@NotNull LDAPConnection connection)
connection
- The connection to be discarded.public void releaseAndReAuthenticateConnection(@NotNull LDAPConnection connection)
connection
- The connection to be released back to the pool after
being re-authenticated.public void releaseDefunctConnection(@NotNull LDAPConnection connection)
releaseDefunctConnection
in class AbstractConnectionPool
connection
- The defunct connection being released.@NotNull public LDAPConnection replaceDefunctConnection(@NotNull LDAPConnection connection) throws LDAPException
replaceDefunctConnection
in class AbstractConnectionPool
connection
- The defunct connection to be replaced.LDAPException
- If a problem is encountered while trying to create
the new connection. Note that even if an exception
is thrown, then the provided connection must have
been properly released as defunct.@NotNull public java.util.Set<OperationType> getOperationTypesToRetryDueToInvalidConnections()
getOperationTypesToRetryDueToInvalidConnections
in class AbstractConnectionPool
public void setRetryFailedOperationsDueToInvalidConnections(@Nullable java.util.Set<OperationType> operationTypes)
LDAPInterface
),
and will not automatically be used for operations processed on connections
checked out of the pool.setRetryFailedOperationsDueToInvalidConnections
in class AbstractConnectionPool
operationTypes
- The types of operations for which to retry failed
operations if they fail in a way that indicates the
associated connection may no longer be usable. It
may be null
or empty to indicate that no
types of operations should be retried.public void setBindRequest(@Nullable BindRequest bindRequest)
bindAndRevertAuthentication
or
releaseAndReAuthenticateConnection
methods are invoked on those
connections.bindRequest
- The bind request that will be used to authenticate new
connections that are established by this pool, or
that will be applied to existing connections via the
bindAndRevertAuthentication
or
releaseAndReAuthenticateConnection
method. It
may be null
if new connections should be
unauthenticated.@NotNull public ServerSet getServerSet()
public void setServerSet(@Nullable ServerSet serverSet)
serverSet
- The server set that should be used to establish new
connections for use in this connection pool. It must
not be null
.@Nullable public java.lang.String getConnectionPoolName()
getConnectionPoolName
in class AbstractConnectionPool
null
if none has been assigned.public void setConnectionPoolName(@Nullable java.lang.String connectionPoolName)
setConnectionPoolName
in class AbstractConnectionPool
connectionPoolName
- The user-friendly name that should be used for
this connection pool.public boolean getCreateIfNecessary()
true
if a new connection should be created if none are
available when a request is received, or false
if an
exception should be thrown to indicate that no connection is
available.public void setCreateIfNecessary(boolean createIfNecessary)
createIfNecessary
- Specifies whether the connection pool should
create a new connection if one is requested when
there are none available.public long getMaxWaitTimeMillis()
public void setMaxWaitTimeMillis(long maxWaitTime)
maxWaitTime
- The maximum length of time in milliseconds to wait for
a connection to become available when trying to obtain
a connection from the pool. A value of zero should be
used to indicate that the pool should not block at all
if no connections are available and that it should
either create a new connection or throw an exception.public long getMaxConnectionAgeMillis()
0L
if no maximum age should be
enforced.public void setMaxConnectionAgeMillis(long maxConnectionAge)
maxConnectionAge
- The maximum length of time in milliseconds that a
connection in this pool may be established before
it should be closed and replaced with another
connection. A value of zero indicates that no
maximum age should be enforced.@Nullable public java.lang.Long getMaxDefunctReplacementConnectionAgeMillis()
null
if the value returned by the
getMaxConnectionAgeMillis()
method should be used.public void setMaxDefunctReplacementConnectionAgeMillis(@Nullable java.lang.Long maxDefunctReplacementConnectionAge)
maxDefunctReplacementConnectionAge
- The maximum connection age that
should be used for connections that were created in order to
replace defunct connections. It may be zero if no maximum age
should be enforced for such connections, or it may be
null
if the value returned by the
getMaxConnectionAgeMillis()
method should be used.public boolean checkConnectionAgeOnRelease()
setMinDisconnectIntervalMillis(long)
method may be used to help mitigate the potential performance impact of
closing and re-establishing multiple connections simultaneously.true
if the connection pool should check connection age in
both the background health check thread and when connections are
released to the pool, or false
if the connection age
should only be checked by the background health check thread.public void setCheckConnectionAgeOnRelease(boolean checkConnectionAgeOnRelease)
setMinDisconnectIntervalMillis(long)
method may be used to help mitigate the potential performance impact of
closing and re-establishing multiple connections simultaneously.checkConnectionAgeOnRelease
- If true
, this indicates that
the connection pool should check
connection age in both the background
health check thread and when
connections are released to the pool.
If false
, this indicates that
the connection pool should check
connection age only in the background
health check thread.public long getMinDisconnectIntervalMillis()
0L
if expired
connections may be closed as quickly as they are identified.public void setMinDisconnectIntervalMillis(long minDisconnectInterval)
minDisconnectInterval
- The minimum length of time in milliseconds
that should pass between connections closed
because they have been established for
longer than the maximum connection age. A
value less than or equal to zero indicates
that no minimum time should be enforced.@NotNull public LDAPConnectionPoolHealthCheck getHealthCheck()
getHealthCheck
in class AbstractConnectionPool
public void setHealthCheck(@NotNull LDAPConnectionPoolHealthCheck healthCheck)
healthCheck
- The health check implementation for this connection
pool. It must not be null
.public long getHealthCheckIntervalMillis()
getHealthCheckIntervalMillis
in class AbstractConnectionPool
public void setHealthCheckIntervalMillis(long healthCheckInterval)
setHealthCheckIntervalMillis
in class AbstractConnectionPool
healthCheckInterval
- The length of time in milliseconds between
periodic background health checks against the
available connections in this pool. The
provided value must be greater than zero.public boolean trySynchronousReadDuringHealthCheck()
true
if health check processing for connections operating
in synchronous mode should include a read attempt with a very
short timeout, or false
if not.public void setTrySynchronousReadDuringHealthCheck(boolean trySynchronousReadDuringHealthCheck)
trySynchronousReadDuringHealthCheck
- Indicates whether health check
processing for connections
operating in synchronous mode
should include attempting to
perform a read from each
connection with a very short
timeout.protected void doHealthCheck()
doHealthCheck
in class AbstractConnectionPool
@NotNull public LDAPConnectionPoolHealthCheckResult invokeHealthCheck(@Nullable LDAPConnectionPoolHealthCheck healthCheck, boolean checkForExpiration)
healthCheck
- The health check to use. If this is
null
, then the pool's
currently-configured health check (if any) will
be used. If this is null
and there is
no health check configured for the pool, then
only a basic set of checks.checkForExpiration
- Indicates whether to check to see if any
connections have been established for longer
than the maximum connection age. If this is
true
then any expired connections will
be closed and replaced with newly-established
connections.@NotNull public LDAPConnectionPoolHealthCheckResult invokeHealthCheck(@Nullable LDAPConnectionPoolHealthCheck healthCheck, boolean checkForExpiration, boolean checkMinConnectionGoal)
healthCheck
- The health check to use. If this is
null
, then the pool's
currently-configured health check (if any)
will be used. If this is null
and
there is no health check configured for the
pool, then only a basic set of checks.checkForExpiration
- Indicates whether to check to see if any
connections have been established for
longer than the maximum connection age. If
this is true
then any expired
connections will be closed and replaced
with newly-established connections.checkMinConnectionGoal
- Indicates whether to check to see if the
currently-available number of connections
is less than the minimum available
connection goal. If this is true
the minimum available connection goal is
greater than zero, and the number of
currently-available connections is less
than the goal, then this method will
attempt to create enough new connections to
reach the goal.public int getCurrentAvailableConnections()
getCurrentAvailableConnections
in class AbstractConnectionPool
public int getMaximumAvailableConnections()
getMaximumAvailableConnections
in class AbstractConnectionPool
public int getMinimumAvailableConnectionGoal()
public void setMinimumAvailableConnectionGoal(int goal)
goal
- The goal for the minimum number of available connections that
the pool should try to maintain for immediate use. A value
less than or equal to zero indicates that the pool should not
try to maintain a minimum number of available connections.@NotNull public LDAPConnectionPoolStatistics getConnectionPoolStatistics()
getConnectionPoolStatistics
in class AbstractConnectionPool
public void shrinkPool(int connectionsToRetain)
connectionsToRetain
- The number of connections that should be
retained for use in the connection pool.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
- If an unexpected problem occurs.public void toString(@NotNull java.lang.StringBuilder buffer)
toString
in class AbstractConnectionPool
buffer
- The buffer to which the string representation should be
appended.