From 8b58a21edd905d8a3bfcacfab2717ab04632ca63 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 13 Sep 2007 23:07:21 +0000
Subject: [PATCH] Update the server so that it is possible to call EmbeddedUtils.startServer to start the server after having previously called EmbeddedUtils.stopServer. Previously, the shutdown process did not leave the server in an adequate state to allow it to be started again later, and only the EmbeddedUtils.restart method would allow a functional restart.

---
 opends/src/server/org/opends/server/core/DirectoryServer.java |   76 +++++++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/core/DirectoryServer.java b/opends/src/server/org/opends/server/core/DirectoryServer.java
index 77c74f3..2aa4e1b 100644
--- a/opends/src/server/org/opends/server/core/DirectoryServer.java
+++ b/opends/src/server/org/opends/server/core/DirectoryServer.java
@@ -8501,8 +8501,80 @@
     shutdownMonitor.waitForMonitor();
 
 
-    // At this point, the server is no longer running.
-    directoryServer.isRunning = false;
+    // At this point, the server is no longer running.  We should destroy the
+    // handle to the previous instance, but we will want to get a new instance
+    // in case the server is to be started again later in the same JVM.  Before
+    // doing that, destroy the previous instance.
+    DirectoryEnvironmentConfig envConfig = directoryServer.environmentConfig;
+    directoryServer.destroy();
+    directoryServer = getNewInstance(envConfig);
+  }
+
+
+
+  /**
+   * Destroy key structures in the current Directory Server instance in a manner
+   * that can help detect any inappropriate cached references to server
+   * components.
+   */
+  private void destroy()
+  {
+    checkSchema                   = true;
+    isBootstrapped                = false;
+    isClientBootstrapped          = false;
+    isRunning                     = false;
+    lockdownMode                  = true;
+    rejectUnauthenticatedRequests = true;
+    shuttingDown                  = true;
+
+    configClass              = null;
+    configFile               = null;
+    configHandler            = null;
+    coreConfigManager        = null;
+    compressedSchema         = null;
+    cryptoManager            = null;
+    defaultBinarySyntax      = null;
+    defaultBooleanSyntax     = null;
+    defaultDNSyntax          = null;
+    defaultIntegerSyntax     = null;
+    defaultStringSyntax      = null;
+    defaultSyntax            = null;
+    entryCache               = null;
+    environmentConfig        = null;
+    objectClassAttributeType = null;
+    schemaDN                 = null;
+    shutdownHook             = null;
+    workQueue                = null;
+
+    if (privateNamingContexts != null)
+    {
+      privateNamingContexts.clear();
+      privateNamingContexts = null;
+    }
+
+    if (publicNamingContexts != null)
+    {
+      publicNamingContexts.clear();
+      publicNamingContexts = null;
+    }
+
+    if (baseDNs != null)
+    {
+      baseDNs.clear();
+      baseDNs = null;
+    }
+
+    if (backends != null)
+    {
+      backends.clear();
+      backends = null;
+    }
+
+    if (schema != null)
+    {
+      schema.destroy();
+      schema = null;
+    }
   }
 
 

--
Gitblit v1.10.0