netscape.ldap
Class LDAPConnSetupMgr

java.lang.Object
  extended by netscape.ldap.LDAPConnSetupMgr
All Implemented Interfaces:
java.io.Serializable

 class LDAPConnSetupMgr
extends java.lang.Object
implements java.io.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
(package private)  class LDAPConnSetupMgr.ServerEntry
          Representation for a server in the server list.
 
Field Summary
(package private)  int m_connectTimeout
          The maximum time to wait to established the connection
(package private)  int m_connSetupDelay
          Delay in ms before another connection setup thread is started.
(package private)  LDAPConnSetupMgr.ServerEntry[] m_dsList
          List of server to use for the connection setup
(package private)  LDAPSocketFactory m_factory
          Socket factory for SSL connections
(package private)  int m_policy
          Connection setup policy (PARALLEL or SERIAL)
(package private) static long serialVersionUID
           
 
Constructor Summary
LDAPConnSetupMgr(LDAPUrl[] urls, LDAPSocketFactory factory)
           
LDAPConnSetupMgr(java.lang.String[] hosts, int[] ports, LDAPSocketFactory factory)
          Constructor
LDAPConnSetupMgr(java.lang.String[] urls, LDAPSocketFactory factory)
           
 
Method Summary
(package private)  boolean breakConnection()
          This is used only by the ldapjdk test libaray to simulate a server problem and to test fail-over and rebind
(package private)  void closeConnection()
          Called when the current connection is terminated by the user.
(package private)  void connectServer(int idx)
          Connect to the server at the given index
(package private)  int getConnectTimeout()
           
(package private)  int getConnSetupDelay()
           
(package private)  java.lang.String getHost()
           
(package private)  LDAPUrl getLDAPUrl()
           
(package private)  int getPort()
           
(package private)  java.net.Socket getSocket()
           
(package private)  void invalidateConnection()
          Called when the current connection is lost.
(package private)  boolean isSecure()
           
(package private)  boolean isUserDisconnected()
          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)  java.net.Socket openConnection()
          Try to open the connection to any of the servers in the list, limiting the time waiting for the connection to be established
(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 policy
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

m_dsList

LDAPConnSetupMgr.ServerEntry[] m_dsList
List of server to use for the connection setup


m_factory

LDAPSocketFactory m_factory
Socket factory for SSL connections


m_policy

int m_policy
Connection setup policy (PARALLEL or SERIAL)


m_connSetupDelay

int m_connSetupDelay
Delay in ms before another connection setup thread is started.


m_connectTimeout

int m_connectTimeout
The maximum time to wait to established the connection

Constructor Detail

LDAPConnSetupMgr

LDAPConnSetupMgr(java.lang.String[] hosts,
                 int[] ports,
                 LDAPSocketFactory factory)
           throws LDAPException
Constructor

Parameters:
host - list of host names to which to connect
port - list of port numbers corresponding to the host list
factory - socket factory for SSL connections
Throws:
LDAPException

LDAPConnSetupMgr

LDAPConnSetupMgr(java.lang.String[] urls,
                 LDAPSocketFactory factory)
           throws LDAPException
Throws:
LDAPException

LDAPConnSetupMgr

LDAPConnSetupMgr(LDAPUrl[] urls,
                 LDAPSocketFactory factory)
           throws LDAPException
Throws:
LDAPException
Method Detail

openConnection

java.net.Socket openConnection()
                         throws LDAPException
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

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

java.net.Socket getSocket()

layerSocket

void layerSocket(LDAPTLSSocketFactory factory)
           throws LDAPException
Layer a new socket over the existing one (used by startTLS)

Throws:
LDAPException

getHost

java.lang.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


connectServer

void connectServer(int idx)
Connect to the server at the given index


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

public java.lang.String toString()
Overrides:
toString in class java.lang.Object