Class JNDIConnectionManager


  • public class JNDIConnectionManager
    extends java.lang.Object
    This class assists the JNDIConnectionImpl implementation with managing (and failing over) multiple servers. It is instantiated as a static singleton by the JDNIConnectionImpl and should not be used outside this package.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void checkForFailBack()
      Handles failback to the primary server.
      protected static boolean checkIfExceptionIsFailable​(javax.naming.NamingException exception)
      This static method is used to determine if an exception of runtime type NamingException is eligable for a server failover.
      void dumpConfiguration()
      dumps the current JNDI configuration.
      DEBUG mode has to be enabled.
      Value of "java.naming.security.credentials" will be skipped
      protected void dumpConfiguration​(java.util.Hashtable<java.lang.String,​java.lang.String> environment)  
      protected void failCurrentServer​(java.lang.Exception reasonForFailure)
      Fails the current server.
      javax.naming.ldap.LdapContext getDirContext​(JNDIConnectionImpl conn, java.lang.String connectDN, char[] connectPassword)
      Fetch a working DirContext connection from the pool.
      java.lang.String getServerURL()  
      boolean isCurrentServerAvailable()
      Checks to see if the current server is actually functioning or not.
      void setConnection​(ConnectionData connectionData)
      Sets the configuration used by the class.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JNDIConnectionManager

        public JNDIConnectionManager()
        Create a new connection manager. setConfig must be called before accessing any other method in this class.
      • JNDIConnectionManager

        public JNDIConnectionManager​(ConnectionData connectionData)
    • Method Detail

      • setConnection

        public void setConnection​(ConnectionData connectionData)
        Sets the configuration used by the class. This method must be called once before any other method is used. It is not part of the constructor to help ease the singleton implementation.
        Parameters:
        connectionData -
      • failCurrentServer

        protected void failCurrentServer​(java.lang.Exception reasonForFailure)
        Fails the current server. Note that this method is time locked so if there is more then one thread that calls this method within the configured ldap timeout period, only one failover command is issued and all other threads are paused for a while. This helps prevent extra burden on the directory server and to many failovers.
        Parameters:
        reasonForFailure - the original exception that prompted the failover cycle.
      • getDirContext

        public javax.naming.ldap.LdapContext getDirContext​(JNDIConnectionImpl conn,
                                                           java.lang.String connectDN,
                                                           char[] connectPassword)
                                                    throws LDAPUnavailableException,
                                                           javax.naming.NamingException
        Fetch a working DirContext connection from the pool. If the current pool is broken it will try all available servers until a working one is found.
        Parameters:
        connectDN -
        connectPassword -
        Returns:
        a working DirContext connection from the pool
        Throws:
        LDAPUnavailableException
        javax.naming.NamingException
      • dumpConfiguration

        public final void dumpConfiguration()
        dumps the current JNDI configuration.
        DEBUG mode has to be enabled.
        Value of "java.naming.security.credentials" will be skipped
      • dumpConfiguration

        protected final void dumpConfiguration​(java.util.Hashtable<java.lang.String,​java.lang.String> environment)
      • getServerURL

        public java.lang.String getServerURL()
      • checkForFailBack

        public void checkForFailBack()
        Handles failback to the primary server. If the current server is the primary server, this method does nothing. Otherwise, if it has been greater then the minimum fail back time, the current server is reset to the primary server.
      • isCurrentServerAvailable

        public boolean isCurrentServerAvailable()
        Checks to see if the current server is actually functioning or not. This is used during failover requests to prevent a ton of failover requests from perpetually failing over the list.
        Returns:
        true if the current server is accessable, false if it is unavailable.
      • checkIfExceptionIsFailable

        protected static boolean checkIfExceptionIsFailable​(javax.naming.NamingException exception)
        This static method is used to determine if an exception of runtime type NamingException is eligable for a server failover.
        Parameters:
        exception -
        Returns:
        true if the exception should be considered a server failure, false if its not.