@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class FewestConnectionsServerSet extends ServerSet
// Create arrays with the addresses and ports of the directory server // instances. String[] addresses = { server1Address, server2Address }; int[] ports = { server1Port, server2Port }; // Create the server set using the address and port arrays. FewestConnectionsServerSet fewestConnectionsSet = new FewestConnectionsServerSet(addresses, ports); // Verify that we can establish a single connection using the server set. LDAPConnection connection = fewestConnectionsSet.getConnection(); RootDSE rootDSEFromConnection = connection.getRootDSE(); connection.close(); // Verify that we can establish a connection pool using the server set. SimpleBindRequest bindRequest = new SimpleBindRequest("uid=pool.user,dc=example,dc=com", "password"); LDAPConnectionPool pool = new LDAPConnectionPool(fewestConnectionsSet, bindRequest, 10); RootDSE rootDSEFromPool = pool.getRootDSE(); pool.close();
Constructor and Description |
---|
FewestConnectionsServerSet(java.lang.String[] addresses,
int[] ports)
Creates a new fewest connections server set with the specified set of
directory server addresses and port numbers.
|
FewestConnectionsServerSet(java.lang.String[] addresses,
int[] ports,
LDAPConnectionOptions connectionOptions)
Creates a new fewest connections server set with the specified set of
directory server addresses and port numbers.
|
FewestConnectionsServerSet(java.lang.String[] addresses,
int[] ports,
javax.net.SocketFactory socketFactory)
Creates a new fewest connections server set with the specified set of
directory server addresses and port numbers.
|
FewestConnectionsServerSet(java.lang.String[] addresses,
int[] ports,
javax.net.SocketFactory socketFactory,
LDAPConnectionOptions connectionOptions)
Creates a new fewest connections server set with the specified set of
directory server addresses and port numbers.
|
FewestConnectionsServerSet(java.lang.String[] addresses,
int[] ports,
javax.net.SocketFactory socketFactory,
LDAPConnectionOptions connectionOptions,
BindRequest bindRequest,
PostConnectProcessor postConnectProcessor)
Creates a new fewest connections server set with the specified set of
directory server addresses and port numbers.
|
FewestConnectionsServerSet(java.lang.String[] addresses,
int[] ports,
javax.net.SocketFactory socketFactory,
LDAPConnectionOptions connectionOptions,
BindRequest bindRequest,
PostConnectProcessor postConnectProcessor,
long blacklistCheckIntervalMillis)
Creates a new fewest connections server set with the specified set of
directory server addresses and port numbers.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String[] |
getAddresses()
Retrieves the addresses of the directory servers to which the connections
should be established.
|
ServerSetBlacklistManager |
getBlacklistManager()
Retrieves the blacklist manager for this server set.
|
LDAPConnection |
getConnection()
Attempts to establish a connection to one of the directory servers in this
server set.
|
LDAPConnection |
getConnection(LDAPConnectionPoolHealthCheck healthCheck)
Attempts to establish a connection to one of the directory servers in this
server set, using the provided health check to further validate the
connection.
|
LDAPConnectionOptions |
getConnectionOptions()
Retrieves the set of connection options that will be used for underlying
connections.
|
int[] |
getPorts()
Retrieves the ports of the directory servers to which the connections
should be established.
|
javax.net.SocketFactory |
getSocketFactory()
Retrieves the socket factory that will be used to establish connections.
|
protected void |
handleConnectionClosed(LDAPConnection connection,
java.lang.String host,
int port,
DisconnectType disconnectType,
java.lang.String message,
java.lang.Throwable cause)
Performs any processing that may be required when the provided connection
is closed.
|
boolean |
includesAuthentication()
Indicates whether connections created by this server set will be
authenticated.
|
boolean |
includesPostConnectProcessing()
Indicates whether connections created by this server set will have
post-connect processing performed.
|
void |
shutDown()
Shuts down this server set and frees any resources associated with it.
|
void |
toString(java.lang.StringBuilder buffer)
Appends a string representation of this server set to the provided buffer.
|
associateConnectionWithThisServerSet, doBindPostConnectAndHealthCheckProcessing, toString
public FewestConnectionsServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports)
addresses
- The addresses of the directory servers to which the
connections should be established. It must not be
null
or empty.ports
- The ports of the directory servers to which the
connections should be established. It must not be
null
, and it must have the same number of
elements as the addresses
array. The order of
elements in the addresses
array must correspond
to the order of elements in the ports
array.public FewestConnectionsServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable LDAPConnectionOptions connectionOptions)
addresses
- The addresses of the directory servers to which
the connections should be established. It must
not be null
or empty.ports
- The ports of the directory servers to which the
connections should be established. It must not
be null
, and it must have the same
number of elements as the addresses
array. The order of elements in the
addresses
array must correspond to the
order of elements in the ports
array.connectionOptions
- The set of connection options to use for the
underlying connections.public FewestConnectionsServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory)
addresses
- The addresses of the directory servers to which the
connections should be established. It must not be
null
or empty.ports
- The ports of the directory servers to which the
connections should be established. It must not be
null
, and it must have the same number of
elements as the addresses
array. The order
of elements in the addresses
array must
correspond to the order of elements in the
ports
array.socketFactory
- The socket factory to use to create the underlying
connections.public FewestConnectionsServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory, @Nullable LDAPConnectionOptions connectionOptions)
addresses
- The addresses of the directory servers to which
the connections should be established. It must
not be null
or empty.ports
- The ports of the directory servers to which the
connections should be established. It must not
be null
, and it must have the same
number of elements as the addresses
array. The order of elements in the
addresses
array must correspond to the
order of elements in the ports
array.socketFactory
- The socket factory to use to create the
underlying connections.connectionOptions
- The set of connection options to use for the
underlying connections.public FewestConnectionsServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory, @Nullable LDAPConnectionOptions connectionOptions, @Nullable BindRequest bindRequest, @Nullable PostConnectProcessor postConnectProcessor)
addresses
- The addresses of the directory servers to
which the connections should be established.
It must not be null
or empty.ports
- The ports of the directory servers to which
the connections should be established. It
must not be null
, and it must have
the same number of elements as the
addresses
array. The order of
elements in the addresses
array must
correspond to the order of elements in the
ports
array.socketFactory
- The socket factory to use to create the
underlying connections.connectionOptions
- The set of connection options to use for the
underlying connections.bindRequest
- The bind request that should be used to
authenticate newly established connections.
It may be null
if this server set
should not perform any authentication.postConnectProcessor
- The post-connect processor that should be
invoked on newly established connections. It
may be null
if this server set should
not perform any post-connect processing.public FewestConnectionsServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory, @Nullable LDAPConnectionOptions connectionOptions, @Nullable BindRequest bindRequest, @Nullable PostConnectProcessor postConnectProcessor, long blacklistCheckIntervalMillis)
addresses
- The addresses of the directory
servers to which the connections
should be established. It must not
be null
or empty.ports
- The ports of the directory servers to
which the connections should be
established. It must not be
null
, and it must have the
same number of elements as the
addresses
array. The order
of elements in the addresses
array must correspond to the order of
elements in the ports
array.socketFactory
- The socket factory to use to create
the underlying connections.connectionOptions
- The set of connection options to use
for the underlying connections.bindRequest
- The bind request that should be used
to authenticate newly established
connections. It may be null
if this server set should not perform
any authentication.postConnectProcessor
- The post-connect processor that
should be invoked on newly
established connections. It may be
null
if this server set
should not perform any post-connect
processing.blacklistCheckIntervalMillis
- The length of time in milliseconds
between checks of servers on the
blacklist to determine whether they
are once again suitable for use. A
value that is less than or equal to
zero indicates that no blacklist
should be maintained.@NotNull public java.lang.String[] getAddresses()
@NotNull public int[] getPorts()
@NotNull public javax.net.SocketFactory getSocketFactory()
@NotNull public LDAPConnectionOptions getConnectionOptions()
public boolean includesAuthentication()
includesAuthentication
in class ServerSet
true
if connections created by this server set will be
authenticated, or false
if not.public boolean includesPostConnectProcessing()
includesPostConnectProcessing
in class ServerSet
true
if connections created by this server set will have
post-connect processing performed, or false
if not.@NotNull public LDAPConnection getConnection() throws LDAPException
ServerSet.includesAuthentication()
must return true if and only if the
connection will also be authenticated, and the
ServerSet.includesPostConnectProcessing()
method must return true if and
only if pre-authentication and post-authentication post-connect processing
will have been performed. The caller may determine the server to which the
connection is established using the
LDAPConnection.getConnectedAddress()
and
LDAPConnection.getConnectedPort()
methods.getConnection
in class ServerSet
LDAPConnection
object that is established to one of the
servers in this server set.LDAPException
- If it is not possible to establish a connection to
any of the servers in this server set.@NotNull public LDAPConnection getConnection(@Nullable LDAPConnectionPoolHealthCheck healthCheck) throws LDAPException
ServerSet.includesAuthentication()
must return true if and only if the
connection will also be authenticated, and the
ServerSet.includesPostConnectProcessing()
method must return true if and
only if pre-authentication and post-authentication post-connect processing
will have been performed. The caller may determine the server to which the
connection is established using the
LDAPConnection.getConnectedAddress()
and
LDAPConnection.getConnectedPort()
methods.getConnection
in class ServerSet
healthCheck
- The health check to use to verify the health of the
newly-created connection. It may be null
if
no additional health check should be performed. If it
is non-null
and this server set performs
authentication, then the health check's
ensureConnectionValidAfterAuthentication
method will be invoked immediately after the bind
operation is processed (regardless of whether the bind
was successful or not). And regardless of whether
this server set performs authentication, the
health check's ensureNewConnectionValid
method must be invoked on the connection to ensure
that it is valid immediately before it is returned.LDAPConnection
object that is established to one of the
servers in this server set.LDAPException
- If it is not possible to establish a connection to
any of the servers in this server set.protected void handleConnectionClosed(@NotNull LDAPConnection connection, @NotNull java.lang.String host, int port, @NotNull DisconnectType disconnectType, @Nullable java.lang.String message, @Nullable java.lang.Throwable cause)
ServerSet.associateConnectionWithThisServerSet(com.unboundid.ldap.sdk.LDAPConnection)
method was called on the connection when it was created by this server set.handleConnectionClosed
in class ServerSet
connection
- The connection that has been closed.host
- The address of the server to which the connection
had been established.port
- The port of the server to which the connection had
been established.disconnectType
- The disconnect type, which provides general
information about the nature of the disconnect.message
- A message that may be associated with the
disconnect. It may be null
if no message
is available.cause
- A Throwable
that was caught and triggered
the disconnect. It may be null
if the
disconnect was not triggered by a client-side
exception or error.@Nullable public ServerSetBlacklistManager getBlacklistManager()
null
if no
blacklist will be maintained.public void shutDown()