|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.unboundid.ldap.sdk.ServerSet
com.unboundid.ldap.sdk.FailoverServerSet
public final class FailoverServerSet
This class provides a server set implementation that will attempt to
establish connections to servers in the order they are provided. If the
first server is unavailable, then it will attempt to connect to the second,
then to the third, etc. Note that this implementation also makes it possible
to use failover between distinct server sets, which means that it will first
attempt to obtain a connection from the first server set and if all attempts
fail, it will proceed to the second set, and so on. This can provide a
significant degree of flexibility in complex environments (e.g., first use a
round robin server set containing servers in the local data center, but if
none of those are available then fail over to a server set with servers in a
remote data center).
// 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. FailoverServerSet failoverSet = new FailoverServerSet(addresses, ports); // Verify that we can establish a single connection using the server set. LDAPConnection connection = failoverSet.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(failoverSet, bindRequest, 10); RootDSE rootDSEFromPool = pool.getRootDSE(); pool.close();This second example demonstrates the process for creating a failover server set which actually fails over between two different data centers (east and west), with each data center containing two servers that will be accessed in a round-robin manner. It will first try to connect to one of the servers in the east data center, and if that attempt fails then it will try to connect to the other server in the east data center. If both of them fail, then it will try to connect to one of the servers in the west data center, and finally as a last resort the other server in the west data center:
// Create a round-robin server set for the servers in the "east" data // center. String[] eastAddresses = { eastServer1Address, eastServer2Address }; int[] eastPorts = { eastServer1Port, eastServer2Port }; RoundRobinServerSet eastSet = new RoundRobinServerSet(eastAddresses, eastPorts); // Create a round-robin server set for the servers in the "west" data // center. String[] westAddresses = { westServer1Address, westServer2Address }; int[] westPorts = { westServer1Port, westServer2Port }; RoundRobinServerSet westSet = new RoundRobinServerSet(westAddresses, westPorts); // Create the failover server set across the east and west round-robin sets. FailoverServerSet failoverSet = new FailoverServerSet(eastSet, westSet); // Verify that we can establish a single connection using the server set. LDAPConnection connection = failoverSet.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(failoverSet, bindRequest, 10); RootDSE rootDSEFromPool = pool.getRootDSE(); pool.close();
Constructor Summary | |
---|---|
FailoverServerSet(java.util.List<ServerSet> serverSets)
Creates a new failover server set that will fail over between the provided server sets. |
|
FailoverServerSet(ServerSet... serverSets)
Creates a new failover server set that will fail over between the provided server sets. |
|
FailoverServerSet(java.lang.String[] addresses,
int[] ports)
Creates a new failover server set with the specified set of directory server addresses and port numbers. |
|
FailoverServerSet(java.lang.String[] addresses,
int[] ports,
LDAPConnectionOptions connectionOptions)
Creates a new failover server set with the specified set of directory server addresses and port numbers. |
|
FailoverServerSet(java.lang.String[] addresses,
int[] ports,
javax.net.SocketFactory socketFactory)
Creates a new failover server set with the specified set of directory server addresses and port numbers. |
|
FailoverServerSet(java.lang.String[] addresses,
int[] ports,
javax.net.SocketFactory socketFactory,
LDAPConnectionOptions connectionOptions)
Creates a new failover server set with the specified set of directory server addresses and port numbers. |
Method Summary | |
---|---|
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. |
java.lang.Long |
getMaxFailoverConnectionAgeMillis()
Retrieves the maximum connection age that should be used for "failover" connections (i.e., connections that are established to any server other than the most-preferred server, or established using any server set other than the most-preferred set). |
ServerSet[] |
getServerSets()
Retrieves the server sets over which failover will occur. |
boolean |
reOrderOnFailover()
Indicates whether the list of servers or server sets used by this failover server set should be re-ordered in the event that a failure is encountered while attempting to establish a connection. |
void |
setMaxFailoverConnectionAgeMillis(java.lang.Long maxFailoverConnectionAge)
Specifies the maximum connection age that should be used for "failover" connections (i.e., connections that are established to any server other than the most-preferred server, or established using any server set other than the most-preferred set). |
void |
setReOrderOnFailover(boolean reOrderOnFailover)
Specifies whether the list of servers or server sets used by this failover server set should be re-ordered in the event that a failure is encountered while attempting to establish a connection. |
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 |
---|
toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FailoverServerSet(java.lang.String[] addresses, 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 FailoverServerSet(java.lang.String[] addresses, int[] ports, 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 FailoverServerSet(java.lang.String[] addresses, int[] ports, 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 FailoverServerSet(java.lang.String[] addresses, int[] ports, javax.net.SocketFactory socketFactory, 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 FailoverServerSet(ServerSet... serverSets)
serverSets
- The server sets between which failover should occur.
It must not be null
or empty.public FailoverServerSet(java.util.List<ServerSet> serverSets)
serverSets
- The server sets between which failover should occur.
It must not be null
or empty.Method Detail |
---|
public ServerSet[] getServerSets()
SingleServerSet
instances.
public boolean reOrderOnFailover()
true
, then any
failed attempt to establish a connection to a server set at the beginning
of the list may cause that server/set to be moved to the end of the list so
that it will be the last one tried on the next attempt.
true
if the order of elements in the associated list of
servers or server sets should be updated if a failure occurs while
attempting to establish a connection, or false
if the
original order should be preserved.public void setReOrderOnFailover(boolean reOrderOnFailover)
true
, then a failed attempt to establish a connection to the server
or server set at the beginning of the list may cause that server to be
moved to the end of the list so that it will be the last server/set tried
on the next attempt.
reOrderOnFailover
- Indicates whether the list of servers or server
sets should be re-ordered in the event that a
failure is encountered while attempting to
establish a connection.public java.lang.Long getMaxFailoverConnectionAgeMillis()
LDAPConnectionPool
, for connections
within that pool.
null
if the maximum
connection age should be determined by the associated connection
pool.public void setMaxFailoverConnectionAgeMillis(java.lang.Long maxFailoverConnectionAge)
LDAPConnectionPool
, for connections
within that pool.
maxFailoverConnectionAge
- The maximum connection age that should be
used for failover connections. It may be
less than or equal to zero to indicate
that no maximum age should apply to such
connections, or null
to indicate
that the maximum connection age should be
determined by the associated connection
pool.public LDAPConnection getConnection() throws LDAPException
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.public LDAPConnection getConnection(LDAPConnectionPoolHealthCheck healthCheck) throws LDAPException
LDAPConnection#getConnectedAddress
and
LDAPConnection#getConnectedPort
methods.
getConnection
in class ServerSet
healthCheck
- The health check to use to make the determination, or
null
if no additional health check should be
performed.
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.public void toString(java.lang.StringBuilder buffer)
toString
in class ServerSet
buffer
- The buffer to which the string representation should be
appended.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |