Package netscape.ldap
Class LDAPConnSetupMgr
java.lang.Object
netscape.ldap.LDAPConnSetupMgr
- All Implemented Interfaces:
Serializable
Makes a connection to a server from a list using "smart" failover.
Connection attempts can be made serially from the same thread, or
in parallel by creating a separate thread after the specified delay.
Connection setup status is preserved for later attempts, so that servers
that are more likely to be available will be tried first.
The total time spent opening a connection can be limited with the
ConnectTimeout
property.
When a connection is successfully created, a socket is opened. The socket is passed to the LDAPConnThread. The LDAPConnThread must call invalidateConnection() if the connection is lost due to a network or server error, or closeConnection() if the connection is deliberately terminated by the user.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) class
Representation for a server in the server list. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
ServerEntry.connSetupStatus possible value.private static final int
private static final int
private static final int
private int
During connection setup, the current count of servers to which connection attmpt has been made(package private) int
The maximum time to wait to established the connectionprivate LDAPException
Last exception occured during connection setup(package private) int
Delay in ms before another connection setup thread is started.private int
Index of the last connected server(package private) LDAPConnSetupMgr.ServerEntry[]
List of server to use for the connection setup(package private) LDAPSocketFactory
Socket factory for SSL connectionsprivate Socket
Original, underlying socket to the server, see layerSocket()(package private) int
Connection setup policy (PARALLEL or SERIAL)private Socket
Socket to the connected serverprivate static final int
private static final int
private static final int
Policy for opening a connection when multiple servers are used(package private) static final long
-
Constructor Summary
ConstructorsConstructorDescriptionLDAPConnSetupMgr
(String[] hosts, int[] ports, LDAPSocketFactory factory) ConstructorLDAPConnSetupMgr
(String[] urls, LDAPSocketFactory factory) LDAPConnSetupMgr
(LDAPUrl[] urls, LDAPSocketFactory factory) -
Method Summary
Modifier and TypeMethodDescription(package private) boolean
This is used only by the ldapjdk test libaray to simulate a server problem and to test fail-over and rebindprivate void
cleanup()
Terminate all concurrently running connection setup threads(package private) void
Called when the current connection is terminated by the user.private void
connect()
(package private) void
connectServer
(int idx) Connect to the server at the given index(package private) int
(package private) int
(package private) String
getHost()
(package private) LDAPUrl
(package private) int
getPort()
private String
(package private) Socket
(package private) void
Called when the current connection is lost.(package private) boolean
isSecure()
(package private) boolean
Check if the user has voluntarily closed the connection(package private) void
layerSocket
(LDAPTLSSocketFactory factory) Layer a new socket over the existing one (used by startTLS)(package private) Socket
Try to open the connection to any of the servers in the list, limiting the time waiting for the connection to be establishedprivate void
Try concurrently to open a new connection a server.private void
Try sequentially to open a new connection to a server.private void
reset()
(package private) void
setConnectTimeout
(int timeout) Sets the maximum time to spend in the openConnection() call(package private) void
setConnSetupDelay
(int delay) Selects the connection failover policyprivate void
Sorts Server List so that servers which are more likely to be available are tried first.toString()
-
Field Details
-
serialVersionUID
static final long serialVersionUID- See Also:
-
SERIAL
private static final int SERIALPolicy for opening a connection when multiple servers are used- See Also:
-
PARALLEL
private static final int PARALLEL- See Also:
-
CONNECTED
private static final int CONNECTEDServerEntry.connSetupStatus possible value. The values also represent the likelihood that the connection will be setup to a server. Lower values have higher priority. See sortDsList() method- See Also:
-
DISCONNECTED
private static final int DISCONNECTED- See Also:
-
NEVER_USED
private static final int NEVER_USED- See Also:
-
INTERRUPTED
private static final int INTERRUPTED- See Also:
-
FAILED
private static final int FAILED- See Also:
-
m_socket
Socket to the connected server -
m_origSocket
Original, underlying socket to the server, see layerSocket() -
m_connException
Last exception occured during connection setup -
m_dsList
LDAPConnSetupMgr.ServerEntry[] m_dsListList of server to use for the connection setup -
m_dsIdx
private int m_dsIdxIndex of the last connected server -
m_factory
LDAPSocketFactory m_factorySocket factory for SSL connections -
m_policy
int m_policyConnection setup policy (PARALLEL or SERIAL) -
m_connSetupDelay
int m_connSetupDelayDelay in ms before another connection setup thread is started. -
m_connectTimeout
int m_connectTimeoutThe maximum time to wait to established the connection -
m_attemptCnt
private transient int m_attemptCntDuring connection setup, the current count of servers to which connection attmpt has been made
-
-
Constructor Details
-
LDAPConnSetupMgr
LDAPConnSetupMgr(String[] hosts, int[] ports, LDAPSocketFactory factory) throws LDAPException Constructor- Parameters:
factory
- socket factory for SSL connectionshost
- list of host names to which to connectport
- list of port numbers corresponding to the host list- Throws:
LDAPException
-
LDAPConnSetupMgr
LDAPConnSetupMgr(String[] urls, LDAPSocketFactory factory) throws LDAPException - Throws:
LDAPException
-
LDAPConnSetupMgr
LDAPConnSetupMgr(LDAPUrl[] urls, LDAPSocketFactory factory) throws LDAPException - Throws:
LDAPException
-
-
Method Details
-
openConnection
Try to open the connection to any of the servers in the list, limiting the time waiting for the connection to be established- Returns:
- connection socket
- Throws:
LDAPException
-
reset
private void reset() -
getServerList
-
connect
private void connect() -
invalidateConnection
void invalidateConnection()Called when the current connection is lost. Put the connected server at the end of the server list for the next connect attempt. -
closeConnection
void closeConnection()Called when the current connection is terminated by the user. Mark the connected server status as DISCONNECTED. This will put it at top of the server list for the next connect attempt. -
getSocket
Socket getSocket() -
layerSocket
Layer a new socket over the existing one (used by startTLS)- Throws:
LDAPException
-
getHost
String getHost() -
getPort
int getPort() -
isSecure
boolean isSecure() -
getLDAPUrl
LDAPUrl getLDAPUrl() -
getConnSetupDelay
int getConnSetupDelay() -
setConnSetupDelay
void setConnSetupDelay(int delay) Selects the connection failover policy- Parameters:
delay
- in seconds for the parallel connection setup policy. Possible values are:
(delay=-1) use serial policy,
(delay=0) start immediately concurrent threads to each specified server
(delay>0) create a new connection setup thread after delay seconds
-
getConnectTimeout
int getConnectTimeout() -
setConnectTimeout
void setConnectTimeout(int timeout) Sets the maximum time to spend in the openConnection() call- Parameters:
timeout
- in seconds to wait for the connection to be established
-
isUserDisconnected
boolean isUserDisconnected()Check if the user has voluntarily closed the connection -
openSerial
private void openSerial()Try sequentially to open a new connection to a server. -
openParallel
private void openParallel()Try concurrently to open a new connection a server. Create a separate thread for each connection attempt. -
connectServer
void connectServer(int idx) Connect to the server at the given index -
cleanup
private void cleanup()Terminate all concurrently running connection setup threads -
sortDsList
private void sortDsList()Sorts Server List so that servers which are more likely to be available are tried first. The likelihood of making a successful connection is determined by the connSetupStatus. Lower values have higher likelihood. Thus, the order of server access is (1) disconnected by the user (2) never used (3) interrupted connection attempt (4) connection setup failed/connection lost -
breakConnection
boolean breakConnection()This is used only by the ldapjdk test libaray to simulate a server problem and to test fail-over and rebind- Returns:
- A flag whether the connection was closed
-
toString
-