From 1a06f8a0f03e724d29dd530b1b8a2d6dd84f2117 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 22 Jun 2009 15:29:11 +0000
Subject: [PATCH] Display a message when the startup timeout is reached informing the user of the existence of the --timeout argument.

---
 opends/src/server/org/opends/server/tools/WaitForFileDelete.java |  147 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 134 insertions(+), 13 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/WaitForFileDelete.java b/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
index 7ce36e3..de268b5 100644
--- a/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
+++ b/opends/src/server/org/opends/server/tools/WaitForFileDelete.java
@@ -30,18 +30,22 @@
 
 
 import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
 import java.io.RandomAccessFile;
 
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.types.NullOutputStream;
 import org.opends.server.util.args.ArgumentException;
 import org.opends.server.util.args.ArgumentParser;
 import org.opends.server.util.args.BooleanArgument;
 import org.opends.server.util.args.IntegerArgument;
 import org.opends.server.util.args.StringArgument;
+import org.opends.server.util.cli.ConsoleApplication;
 
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.messages.CoreMessages.*;
-import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
 
 
@@ -51,7 +55,7 @@
  * deleted before exiting.  It can be used in the process of confirming that the
  * server has completed its startup or shutdown process.
  */
-public class WaitForFileDelete
+public class WaitForFileDelete extends ConsoleApplication
 {
   /**
    * The fully-qualified name of this class.
@@ -86,6 +90,18 @@
 
 
   /**
+   * Constructor for the WaitForFileDelete object.
+   *
+   * @param out the print stream to use for standard output.
+   * @param err the print stream to use for standard error.
+   * @param in the input stream to use for standard input.
+   */
+  public WaitForFileDelete(PrintStream out, PrintStream err, InputStream in)
+  {
+    super(in, out, err);
+  }
+
+  /**
    * Processes the command-line arguments and initiates the process of waiting
    * for the file to be removed.
    *
@@ -93,19 +109,66 @@
    */
   public static void main(String[] args)
   {
+    int retCode = mainCLI(args, true, System.out, System.err, System.in);
+
+    System.exit(retCode);
+  }
+
+  /**
+   * Processes the command-line arguments and initiates the process of waiting
+   * for the file to be removed.
+   *
+   * @param  args              The command-line arguments provided to this
+   *                           program.
+   * @param initializeServer   Indicates whether to initialize the server.
+   * @param  outStream         The output stream to use for standard output, or
+   *                           <CODE>null</CODE> if standard output is not
+   *                           needed.
+   * @param  errStream         The output stream to use for standard error, or
+   *                           <CODE>null</CODE> if standard error is not
+   *                           needed.
+   * @param  inStream          The input stream to use for standard input.
+   * @return The error code.
+   */
+
+  public static int mainCLI(String[] args, boolean initializeServer,
+      OutputStream outStream, OutputStream errStream, InputStream inStream)
+  {
+    int exitCode;
+    PrintStream out;
+    if (outStream == null)
+    {
+      out = NullOutputStream.printStream();
+    }
+    else
+    {
+      out = new PrintStream(outStream);
+    }
+
+    PrintStream err;
+    if (errStream == null)
+    {
+      err = NullOutputStream.printStream();
+    }
+    else
+    {
+      err = new PrintStream(errStream);
+    }
     try
     {
-      int exitCode = mainWait(args);
+      WaitForFileDelete wffd = new WaitForFileDelete(out, err, System.in);
+      exitCode = wffd.mainWait(args);
       if (exitCode != EXIT_CODE_SUCCESS)
       {
-        System.exit(filterExitCode(exitCode));
+        exitCode = filterExitCode(exitCode);
       }
     }
     catch (Exception e)
     {
       e.printStackTrace();
-      System.exit(EXIT_CODE_INTERNAL_ERROR);
+      exitCode = EXIT_CODE_INTERNAL_ERROR;
     }
+    return exitCode;
   }
 
 
@@ -115,11 +178,18 @@
    * to be removed.
    *
    * @param  args  The command-line arguments provided to this program.
+   * @param  out         The output stream to use for standard output, or
+   *                           <CODE>null</CODE> if standard output is not
+   *                           needed.
+   * @param  err         The output stream to use for standard error, or
+   *                           <CODE>null</CODE> if standard error is not
+   *                           needed.
+   * @param  inStream          The input stream to use for standard input.
    *
    * @return  An integer value of zero if the file was deleted successfully, or
    *          some other value if a problem occurred.
    */
-  public static int mainWait(String[] args)
+  private int mainWait(String[] args)
   {
     // Create all of the command-line arguments for this program.
     BooleanArgument showUsage      = null;
@@ -188,7 +258,7 @@
     catch (ArgumentException ae)
     {
       Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
-      System.err.println(wrapText(message, MAX_LINE_WIDTH));
+      println(message);
       return EXIT_CODE_INTERNAL_ERROR;
     }
 
@@ -202,8 +272,8 @@
     {
       Message message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
 
-      System.err.println(wrapText(message, MAX_LINE_WIDTH));
-      System.err.println(argParser.getUsage());
+      println(message);
+      println(Message.raw(argParser.getUsage()));
       return EXIT_CODE_INTERNAL_ERROR;
     }
 
@@ -243,7 +313,7 @@
       {
         Message message = WARN_WAIT4DEL_CANNOT_OPEN_LOG_FILE.get(
                 logFilePath.getValue(), String.valueOf(e));
-        System.err.println(wrapText(message, MAX_LINE_WIDTH));
+        println(message);
 
         logFile = null;
       }
@@ -272,7 +342,7 @@
         {
           Message message = WARN_WAIT4DEL_CANNOT_OPEN_OUTPUT_FILE.get(
                   outputFilePath.getValue(), String.valueOf(e));
-          System.err.println(wrapText(message, MAX_LINE_WIDTH));
+          println(message);
 
           outputFile = null;
         }
@@ -315,8 +385,8 @@
             {
               if (outputFile == null)
               {
-                System.out.write(logBuffer, 0, bytesRead);
-                System.out.flush();
+                getOutputStream().write(logBuffer, 0, bytesRead);
+                getOutputStream().flush();
               }
               else
               {
@@ -360,6 +430,9 @@
 
     if (targetFile.exists())
     {
+      println(ERR_TIMEOUT_DURING_STARTUP.get(
+          Integer.parseInt(timeout.getValue()),
+          timeout.getLongIdentifier()));
       return EXIT_CODE_TIMEOUT;
     }
     else
@@ -367,5 +440,53 @@
       return EXIT_CODE_SUCCESS;
     }
   }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isAdvancedMode()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isInteractive()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isMenuDrivenMode()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isQuiet()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isScriptFriendly()
+  {
+    return false;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isVerbose()
+  {
+    return false;
+  }
 }
 

--
Gitblit v1.10.0