From 12528a2548d419b1d48d1ec70f0f9ae3a94c0b20 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 23 Oct 2009 19:44:22 +0000
Subject: [PATCH] Fix for issue 4313 (Control-panel stop triggers authentication pop-up) After getting the return code from stop-ds, verify that the server released its lock on the file used to test that it is running.

---
 opends/src/guitools/org/opends/guitools/controlpanel/task/StopServerTask.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/opends/src/guitools/org/opends/guitools/controlpanel/task/StopServerTask.java b/opends/src/guitools/org/opends/guitools/controlpanel/task/StopServerTask.java
index ece3aef..5545896 100644
--- a/opends/src/guitools/org/opends/guitools/controlpanel/task/StopServerTask.java
+++ b/opends/src/guitools/org/opends/guitools/controlpanel/task/StopServerTask.java
@@ -29,6 +29,8 @@
 
 import static org.opends.messages.AdminToolMessages.*;
 
+import java.io.File;
+
 import javax.swing.SwingUtilities;
 
 import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
@@ -79,6 +81,7 @@
     super.runTask();
     if (state == State.FINISHED_SUCCESSFULLY)
     {
+      // Verify that the server is actually stopped
       SwingUtilities.invokeLater(new Runnable()
       {
         public void run()
@@ -98,4 +101,56 @@
   {
     return getCommandLinePath("stop-ds");
   }
+
+  /**
+   * Method called just after calling the command-line.  To be overwritten
+   * by the inheriting classes.
+   */
+  protected void postCommandLine()
+  {
+    if (returnCode != 0)
+    {
+      state = State.FINISHED_WITH_ERROR;
+    }
+    else
+    {
+      File f = new File(getInfo().getServerDescriptor().getInstancePath());
+      // Check that the server is actually stopped.
+      boolean stopped = !Utilities.isServerRunning(f);
+      int nTries = 20;
+      while (!stopped && nTries > 0)
+      {
+        try
+        {
+          Thread.sleep(700);
+        }
+        catch (Throwable t)
+        {
+        }
+        stopped = !Utilities.isServerRunning(f);
+        nTries --;
+      }
+      if (!stopped)
+      {
+        SwingUtilities.invokeLater(new Runnable()
+        {
+          public void run()
+          {
+            getProgressDialog().appendProgressHtml(
+                Utilities.applyFont(
+                    "<br>"+
+                    ERR_CTRL_PANEL_STOPPING_SERVER_POST_CMD_LINE.get(
+                        getCommandLinePath("stop-ds"))+"<br>",
+                        ColorAndFontConstants.progressFont));
+          }
+        });
+        returnCode = -1;
+        state = State.FINISHED_WITH_ERROR;
+      }
+      else
+      {
+        state = State.FINISHED_SUCCESSFULLY;
+      }
+    }
+  }
 }

--
Gitblit v1.10.0