From e5bf2a8578b2316d866a45f93b259570c687b10b Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Tue, 19 Sep 2006 06:58:32 +0000
Subject: [PATCH] Pb description (issue #648): The Jmx connector handler is starting a local RMI registry on port 1689 (actually the port specified in the config.ldif file). Even if you stop the DS server, but if the process is keeping alive, the RMI registry will remain active and will still listen on this port.

---
 opends/src/server/org/opends/server/protocols/jmx/RmiConnector.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/jmx/RmiConnector.java b/opends/src/server/org/opends/server/protocols/jmx/RmiConnector.java
index 4e5c15e..4fe039a 100644
--- a/opends/src/server/org/opends/server/protocols/jmx/RmiConnector.java
+++ b/opends/src/server/org/opends/server/protocols/jmx/RmiConnector.java
@@ -26,9 +26,13 @@
  */
 package org.opends.server.protocols.jmx;
 
+import java.io.IOException;
+import java.rmi.NoSuchObjectException;
 import java.rmi.RemoteException;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
+import java.rmi.server.RMISocketFactory;
+import java.rmi.server.UnicastRemoteObject;
 import java.util.HashMap;
 
 import javax.net.ssl.SSLSocketFactory;
@@ -116,6 +120,16 @@
    */
   private RmiAuthenticator rmiAuthenticator;
 
+  /**
+   * The reference to the created RMI registry.
+   */
+  private Registry registry = null;
+
+  /**
+   * The Underlying Socket factory.
+   */
+  OpendsRmiServerSocketFactory rmiSsf;
+
   // ===================================================================
   // CONSTRUCTOR
   // ===================================================================
@@ -210,8 +224,12 @@
     {
       //
       // TODO Not yet implemented: If the host has several interfaces
-      LocateRegistry.createRegistry(registryPort);
-
+      if (registry == null)
+      {
+        rmiSsf = new OpendsRmiServerSocketFactory();
+        registry = LocateRegistry.createRegistry(registryPort,
+            RMISocketFactory.getDefaultSocketFactory(), rmiSsf);
+      }
     }
     catch (RemoteException re)
     {
@@ -232,6 +250,7 @@
         //
         // 'ping' the registry
         reg.list();
+        registry = reg;
       }
       catch (Exception e)
       {
@@ -455,7 +474,34 @@
     }
     catch (Exception e)
     {
+      // TODO Log an error message
       assert debugException(CLASS_NAME, "finalizeConnectionHandler", e);
     }
+
+    //
+    // Stop the RMI registry
+    try
+    {
+      UnicastRemoteObject.unexportObject(registry, true);
+    }
+    catch (NoSuchObjectException e)
+    {
+      // TODO Log an error message
+      assert debugException(CLASS_NAME, "finalizeConnectionHandler", e);
+    }
+    registry = null;
+
+    //
+    // Close the socket
+    try
+    {
+      rmiSsf.close();
+    }
+    catch (IOException e)
+    {
+      // TODO Log an error message
+      assert debugException(CLASS_NAME, "finalizeConnectionHandler", e);
+    }
+
   }
 }

--
Gitblit v1.10.0