From dc6bbc9fbe92f7db73e4e3105a0ba371e7ce2f65 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Wed, 19 Sep 2007 17:03:37 +0000
Subject: [PATCH] This commit would clarifies the local operation vs. task scheduling behavior by:

---
 opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java b/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
index 9d7b17b..9e4020d 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -56,6 +56,13 @@
  */
 public abstract class TaskTool implements TaskScheduleInformation {
 
+  /**
+   * Magic value used to indicate that the user would like to schedule
+   * this operation to run immediately as a task as opposed to running
+   * the operation in the local VM.
+   */
+  public static final String NOW = "0";
+
   LDAPConnectionArgumentParser argParser;
 
   StringArgument startArg;
@@ -85,8 +92,8 @@
   protected LDAPConnectionArgumentParser createArgParser(String className,
                                            Message toolDescription)
   {
-    LDAPConnectionArgumentParser argParser = new LDAPConnectionArgumentParser(
-            className, toolDescription, false);
+    argParser = new LDAPConnectionArgumentParser(className,
+            toolDescription, false);
 
     try {
       startArg =
@@ -113,7 +120,7 @@
    * @throws ArgumentException if there is a problem with the arguments
    */
   protected void validateTaskArgs() throws ArgumentException {
-    if (startArg.isPresent()) {
+    if (startArg.isPresent() && !NOW.equals(startArg.getValue())) {
       try {
         StaticUtils.parseDateTimeString(startArg.getValue());
       } catch (ParseException pe) {
@@ -128,10 +135,14 @@
   public Date getStartDateTime() {
     Date start = null;
     if (startArg != null && startArg.isPresent()) {
-      try {
-        start = StaticUtils.parseDateTimeString(startArg.getValue());
-      } catch (ParseException pe) {
-        // ignore; valiidated in validateTaskArgs()
+      if (NOW.equals(startArg.getValue())) {
+        start = new Date();
+      } else {
+        try {
+          start = StaticUtils.parseDateTimeString(startArg.getValue());
+        } catch (ParseException pe) {
+          // ignore; valiidated in validateTaskArgs()
+        }
       }
     }
     return start;
@@ -153,7 +164,7 @@
                         PrintStream out, PrintStream err) {
     int ret;
 
-    if (argParser.isLdapOperation())
+    if (startArg.isPresent())
     {
       if (initializeServer)
       {
@@ -193,7 +204,7 @@
         }
         ret = 0;
       } catch (LDAPConnectionException e) {
-        Message message = ERR_LDAP_CONN_CANNOT_CONNECT.get(e.getMessage());
+        Message message = ERR_TASK_TOOL_START_TIME_NO_LDAP.get(e.getMessage());
         if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
         ret = 1;
       } catch (IOException ioe) {
@@ -213,6 +224,10 @@
         if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
         ret = 1;
       }
+    } else if (argParser.argumentsPresent()) {
+      Message message = ERR_TASK_TOOL_LDAP_NO_START_TIME.get();
+      if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
+      ret = 1;
     } else {
       ret = processLocal(initializeServer, out, err);
     }

--
Gitblit v1.10.0