Package com.unboundid.ldap.sdk
Class FastestConnectServerSet
- java.lang.Object
-
- com.unboundid.ldap.sdk.ServerSet
-
- com.unboundid.ldap.sdk.FastestConnectServerSet
-
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class FastestConnectServerSet extends ServerSet
This class provides a server set implementation that will attempt to establish connections to all associated servers in parallel, keeping the one that was first to be successfully established and closing all others.
Note that this server set implementation may only be used in conjunction with connection options that allow the associated socket factory to create multiple connections in parallel. If theLDAPConnectionOptions.allowConcurrentSocketFactoryUse
method returns false for the associated connection options, then thegetConnection
methods will throw an exception.
Example
The following example demonstrates the process for creating a fastest connect server set that may be used to establish connections to either of two servers. When using the server set to attempt to create a connection, it will try both in parallel and will return the first connection that it is able to establish:// 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. FastestConnectServerSet fastestConnectSet = new FastestConnectServerSet(addresses, ports); // Verify that we can establish a single connection using the server set. LDAPConnection connection = fastestConnectSet.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(fastestConnectSet, bindRequest, 10); RootDSE rootDSEFromPool = pool.getRootDSE(); pool.close();
-
-
Constructor Summary
Constructors Constructor Description FastestConnectServerSet(java.lang.String[] addresses, int[] ports)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers.FastestConnectServerSet(java.lang.String[] addresses, int[] ports, LDAPConnectionOptions connectionOptions)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers.FastestConnectServerSet(java.lang.String[] addresses, int[] ports, javax.net.SocketFactory socketFactory)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers.FastestConnectServerSet(java.lang.String[] addresses, int[] ports, javax.net.SocketFactory socketFactory, LDAPConnectionOptions connectionOptions)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers.FastestConnectServerSet(java.lang.String[] addresses, int[] ports, javax.net.SocketFactory socketFactory, LDAPConnectionOptions connectionOptions, BindRequest bindRequest, PostConnectProcessor postConnectProcessor)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String[]
getAddresses()
Retrieves the addresses of the directory servers to which the connections should be established.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.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
toString(java.lang.StringBuilder buffer)
Appends a string representation of this server set to the provided buffer.-
Methods inherited from class com.unboundid.ldap.sdk.ServerSet
associateConnectionWithThisServerSet, doBindPostConnectAndHealthCheckProcessing, handleConnectionClosed, shutDown, toString
-
-
-
-
Constructor Detail
-
FastestConnectServerSet
public FastestConnectServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers. It will use the default socket factory provided by the JVM to create the underlying sockets.- Parameters:
addresses
- The addresses of the directory servers to which the connections should be established. It must not benull
or empty.ports
- The ports of the directory servers to which the connections should be established. It must not benull
, and it must have the same number of elements as theaddresses
array. The order of elements in theaddresses
array must correspond to the order of elements in theports
array.
-
FastestConnectServerSet
public FastestConnectServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable LDAPConnectionOptions connectionOptions)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers. It will use the default socket factory provided by the JVM to create the underlying sockets.- Parameters:
addresses
- The addresses of the directory servers to which the connections should be established. It must not benull
or empty.ports
- The ports of the directory servers to which the connections should be established. It must not benull
, and it must have the same number of elements as theaddresses
array. The order of elements in theaddresses
array must correspond to the order of elements in theports
array.connectionOptions
- The set of connection options to use for the underlying connections.
-
FastestConnectServerSet
public FastestConnectServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers. It will use the provided socket factory to create the underlying sockets.- Parameters:
addresses
- The addresses of the directory servers to which the connections should be established. It must not benull
or empty.ports
- The ports of the directory servers to which the connections should be established. It must not benull
, and it must have the same number of elements as theaddresses
array. The order of elements in theaddresses
array must correspond to the order of elements in theports
array.socketFactory
- The socket factory to use to create the underlying connections.
-
FastestConnectServerSet
public FastestConnectServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory, @Nullable LDAPConnectionOptions connectionOptions)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers. It will use the provided socket factory to create the underlying sockets.- Parameters:
addresses
- The addresses of the directory servers to which the connections should be established. It must not benull
or empty.ports
- The ports of the directory servers to which the connections should be established. It must not benull
, and it must have the same number of elements as theaddresses
array. The order of elements in theaddresses
array must correspond to the order of elements in theports
array.socketFactory
- The socket factory to use to create the underlying connections.connectionOptions
- The set of connection options to use for the underlying connections.
-
FastestConnectServerSet
public FastestConnectServerSet(@NotNull java.lang.String[] addresses, @NotNull int[] ports, @Nullable javax.net.SocketFactory socketFactory, @Nullable LDAPConnectionOptions connectionOptions, @Nullable BindRequest bindRequest, @Nullable PostConnectProcessor postConnectProcessor)
Creates a new fastest connect server set with the specified set of directory server addresses and port numbers. It will use the provided socket factory to create the underlying sockets.- Parameters:
addresses
- The addresses of the directory servers to which the connections should be established. It must not benull
or empty.ports
- The ports of the directory servers to which the connections should be established. It must not benull
, and it must have the same number of elements as theaddresses
array. The order of elements in theaddresses
array must correspond to the order of elements in theports
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 benull
if this server set should not perform any authentication.postConnectProcessor
- The post-connect processor that should be invoked on newly-established connections. It may benull
if this server set should not perform any post-connect processing.
-
-
Method Detail
-
getAddresses
@NotNull public java.lang.String[] getAddresses()
Retrieves the addresses of the directory servers to which the connections should be established.- Returns:
- The addresses of the directory servers to which the connections should be established.
-
getPorts
@NotNull public int[] getPorts()
Retrieves the ports of the directory servers to which the connections should be established.- Returns:
- The ports of the directory servers to which the connections should be established.
-
getSocketFactory
@NotNull public javax.net.SocketFactory getSocketFactory()
Retrieves the socket factory that will be used to establish connections.- Returns:
- The socket factory that will be used to establish connections.
-
getConnectionOptions
@NotNull public LDAPConnectionOptions getConnectionOptions()
Retrieves the set of connection options that will be used for underlying connections.- Returns:
- The set of connection options that will be used for underlying connections.
-
includesAuthentication
public boolean includesAuthentication()
Indicates whether connections created by this server set will be authenticated.- Overrides:
includesAuthentication
in classServerSet
- Returns:
true
if connections created by this server set will be authenticated, orfalse
if not.
-
includesPostConnectProcessing
public boolean includesPostConnectProcessing()
Indicates whether connections created by this server set will have post-connect processing performed.- Overrides:
includesPostConnectProcessing
in classServerSet
- Returns:
true
if connections created by this server set will have post-connect processing performed, orfalse
if not.
-
getConnection
@NotNull public LDAPConnection getConnection() throws LDAPException
Attempts to establish a connection to one of the directory servers in this server set. The connection that is returned must be established. TheServerSet.includesAuthentication()
must return true if and only if the connection will also be authenticated, and theServerSet.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 theLDAPConnection.getConnectedAddress()
andLDAPConnection.getConnectedPort()
methods.- Specified by:
getConnection
in classServerSet
- Returns:
- An
LDAPConnection
object that is established to one of the servers in this server set. - Throws:
LDAPException
- If it is not possible to establish a connection to any of the servers in this server set.
-
getConnection
@NotNull public LDAPConnection getConnection(@Nullable LDAPConnectionPoolHealthCheck healthCheck) throws LDAPException
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. The connection that is returned must be established. TheServerSet.includesAuthentication()
must return true if and only if the connection will also be authenticated, and theServerSet.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 theLDAPConnection.getConnectedAddress()
andLDAPConnection.getConnectedPort()
methods.- Overrides:
getConnection
in classServerSet
- Parameters:
healthCheck
- The health check to use to verify the health of the newly-created connection. It may benull
if no additional health check should be performed. If it is non-null
and this server set performs authentication, then the health check'sensureConnectionValidAfterAuthentication
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'sensureNewConnectionValid
method must be invoked on the connection to ensure that it is valid immediately before it is returned.- Returns:
- An
LDAPConnection
object that is established to one of the servers in this server set. - Throws:
LDAPException
- If it is not possible to establish a connection to any of the servers in this server set.
-
-