From aa9e57a11efc74e6abba5a47da2305ce1f70c65e Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Sun, 08 Jul 2007 00:05:17 +0000
Subject: [PATCH] Update the LDAP and JMX connection handlers so that they attempt to bind a server socket to the configured port for all appropriate addresses during the initialization phase. This should provide a reliable mechanism for determining whether the connection handler will be allowed to start, and it will be more accurate and faster than the earlier attempt to achieve the same result using SetupUtils.canUseAsPort().
---
opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
index a6dbc80..4e9d163 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
+++ b/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);
}
--
Gitblit v1.10.0