mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

neil_a_wilson
08.05.2007 aa9e57a11efc74e6abba5a47da2305ce1f70c65e
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
@@ -37,8 +37,10 @@
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
@@ -571,9 +573,9 @@
  /**
   * {@inheritDoc}
   */
  public void initializeConnectionHandler(
      LDAPConnectionHandlerCfg config)
      throws ConfigException, InitializationException {
  public void initializeConnectionHandler(LDAPConnectionHandlerCfg config)
         throws ConfigException, InitializationException
  {
    // SSL and StartTLS are mutually exclusive.
    if (config.isAllowStartTLS() && config.isUseSSL()) {
      int msgID = MSGID_LDAP_CONNHANDLER_CANNOT_HAVE_SSL_AND_STARTTLS;
@@ -723,6 +725,50 @@
    // Perform any additional initialization that might be required.
    statTracker = new LDAPStatistics(handlerName + " Statistics");
    // Attempt to bind to the listen port on all configured addresses to
    // verify whether the connection handler will be able to start.
    LinkedList<ServerSocket> testListenSockets = new LinkedList<ServerSocket>();
    try
    {
      for (InetAddress a : listenAddresses)
      {
        try
        {
          ServerSocket s = new ServerSocket();
          s.setReuseAddress(true);
          s.bind(new InetSocketAddress(a, listenPort));
          testListenSockets.add(s);
        }
        catch (IOException e)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
          }
          int    msgID   = MSGID_LDAP_CONNHANDLER_CANNOT_BIND;
          String message = getMessage(msgID, String.valueOf(config.dn()),
                                      a.getHostAddress(), listenPort,
                                      getExceptionMessage(e));
          logError(ErrorLogCategory.CONNECTION_HANDLING,
                   ErrorLogSeverity.SEVERE_ERROR, message, msgID);
          throw new InitializationException(msgID, message);
        }
      }
    }
    finally
    {
      for (ServerSocket s : testListenSockets)
      {
        try
        {
          s.close();
        } catch (Exception e) {}
      }
    }
    // Create and start the request handlers.
    requestHandlers = new LDAPRequestHandler[numRequestHandlers];
    for (int i = 0; i < numRequestHandlers; i++) {
@@ -733,6 +779,7 @@
      requestHandlers[i].start();
    }
    // Register this as a change listener.
    config.addLDAPChangeListener(this);
  }