From cd7ddcc30ed1b2cedf327e3c45185f815bf7ca29 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 02 Mar 2007 17:04:03 +0000
Subject: [PATCH] Allow the user to specify the JMX port using *j* option during the cli installation and using configure script. In the QuickSetup I added some code to *temporarily* select a port that is not being used for JMX.  Today we do not inform the user of the existence of this port so this approach does not make things much worse and reduces the changes of port conflicts in general.  Even in the case where we are not installing multiple instances of OpenDS the port 1689 might be in use by another process.

---
 opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java b/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
index 9f7a9ed..4a17afc 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/QuickSetup.java
@@ -64,6 +64,7 @@
 import org.opends.quicksetup.util.BackgroundTask;
 import org.opends.quicksetup.util.ProgressMessageFormatter;
 import org.opends.quicksetup.util.Utils;
+import org.opends.server.util.SetupUtils;
 
 /**
  * This class is responsible for doing the following:
@@ -873,6 +874,12 @@
       displayFieldInvalid(FieldName.DIRECTORY_MANAGER_PWD_CONFIRM, false);
     }
 
+    int defaultJMXPort = getDefaultJMXPort();
+    if (defaultJMXPort != -1)
+    {
+      getUserInstallData().setServerJMXPort(defaultJMXPort);
+    }
+
     if (errorMsgs.size() > 0)
     {
       throw new UserInstallDataException(Step.SERVER_SETTINGS,
@@ -1168,6 +1175,7 @@
     {
       defaultUserData.setServerPort(defaultPort);
     }
+
     defaultUserData.setDirectoryManagerDn("cn=Directory Manager");
 
     defaultUserData.setDataOptions(defaultDataOptions);
@@ -1471,6 +1479,27 @@
   }
 
   /**
+   * Provides the port that will be used by default for JMX.
+   *
+   * @return the port X689 if it is available and we can use and -1 if not.
+   */
+  private int getDefaultJMXPort()
+  {
+    int defaultJMXPort = -1;
+
+    for (int i=0;i<65000 && (defaultJMXPort == -1);i+=1000)
+    {
+      int port = i + SetupUtils.getDefaultJMXPort();
+      if (Utils.canUseAsPort(port))
+      {
+        defaultJMXPort = port;
+      }
+    }
+    return defaultJMXPort;
+  }
+
+
+  /**
    * Returns the number of free disk space in bytes required to install Open DS
    *
    * For the moment we just return 15 Megabytes. TODO we might want to have

--
Gitblit v1.10.0