@ThreadSafety(level=COMPLETELY_THREADSAFE) public final class LDAPThreadLocalConnectionPool extends AbstractConnectionPool
LDAPConnectionPool
class, as is the manner in which
applications should interact with it. See the class-level documentation for
the LDAPConnectionPool
class for additional information and examples.
LDAPConnectionPool
class is that this implementation does not
currently support periodic background health checks. You can define health
checks that will be invoked when a new connection is created, just before it
is checked out for use, just after it is released, and if an error occurs
while using the connection, but it will not maintain a separate background
threadConstructor and Description |
---|
LDAPThreadLocalConnectionPool(LDAPConnection connection)
Creates a new LDAP thread-local connection pool in which all connections
will be clones of the provided connection.
|
LDAPThreadLocalConnectionPool(LDAPConnection connection,
PostConnectProcessor postConnectProcessor)
Creates a new LDAP thread-local connection pool in which all connections
will be clones of the provided connection.
|
LDAPThreadLocalConnectionPool(ServerSet serverSet,
BindRequest bindRequest)
Creates a new LDAP thread-local connection pool which will use the provided
server set and bind request for creating new connections.
|
LDAPThreadLocalConnectionPool(ServerSet serverSet,
BindRequest bindRequest,
PostConnectProcessor postConnectProcessor)
Creates a new LDAP thread-local connection pool which will use the provided
server set and bind request for creating new connections.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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 |
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.
|
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.
|
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 |
setConnectionPoolName(java.lang.String connectionPoolName)
Specifies the user-friendly name that should be used for this connection
pool.
|
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 |
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 |
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 |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this connection pool to the provided
buffer.
|
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 LDAPThreadLocalConnectionPool(@NotNull LDAPConnection connection) 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.LDAPException
- If the provided connection cannot be used to
initialize the pool. If this is thrown, then all
connections associated with the pool (including the
one provided as an argument) will be closed.public LDAPThreadLocalConnectionPool(@NotNull LDAPConnection connection, @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.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. If this is thrown, then all
connections associated with the pool (including the
one provided as an argument) will be closed.public LDAPThreadLocalConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest)
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.public LDAPThreadLocalConnectionPool(@NotNull ServerSet serverSet, @Nullable BindRequest bindRequest, @Nullable PostConnectProcessor postConnectProcessor)
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.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
.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.public void releaseConnection(@NotNull LDAPConnection connection)
releaseConnection
in class AbstractConnectionPool
connection
- The connection to be released back to the pool.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(@NotNull 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 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.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.protected void doHealthCheck()
doHealthCheck
in class AbstractConnectionPool
public int getCurrentAvailableConnections()
getCurrentAvailableConnections
in class AbstractConnectionPool
public int getMaximumAvailableConnections()
getMaximumAvailableConnections
in class AbstractConnectionPool
@NotNull public LDAPConnectionPoolStatistics getConnectionPoolStatistics()
getConnectionPoolStatistics
in class AbstractConnectionPool
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.