From 39db72786ec179e67e3c1c0c71a2e93672999ea5 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Thu, 03 Dec 2009 18:04:49 +0000
Subject: [PATCH] Split SDK from server code and add build/packaging infrastructure.

---
 sdk/src/org/opends/sdk/tools/SearchRate.java |  138 +++++++++++++++++++++++----------------------
 1 files changed, 70 insertions(+), 68 deletions(-)

diff --git a/sdk/src/org/opends/sdk/tools/SearchRate.java b/sdk/src/org/opends/sdk/tools/SearchRate.java
index b3c157e..a5d380d 100644
--- a/sdk/src/org/opends/sdk/tools/SearchRate.java
+++ b/sdk/src/org/opends/sdk/tools/SearchRate.java
@@ -29,9 +29,9 @@
 
 
 
-import static org.opends.messages.ToolMessages.*;
-import static org.opends.server.tools.ToolConstants.*;
-import static org.opends.server.util.StaticUtils.filterExitCode;
+import static com.sun.opends.sdk.util.Messages.*;
+import static org.opends.sdk.tools.ToolConstants.*;
+import static org.opends.sdk.tools.Utils.*;
 
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -40,12 +40,14 @@
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.opends.messages.Message;
 import org.opends.sdk.*;
 import org.opends.sdk.requests.Requests;
 import org.opends.sdk.requests.SearchRequest;
-import org.opends.sdk.responses.*;
-import org.opends.server.util.cli.ConsoleApplication;
+import org.opends.sdk.responses.Result;
+import org.opends.sdk.responses.SearchResultEntry;
+import org.opends.sdk.responses.SearchResultReference;
+
+import com.sun.opends.sdk.util.Message;
 
 
 
@@ -60,15 +62,15 @@
 
   /**
    * The main method for SearchRate tool.
-   * 
+   *
    * @param args
    *          The command-line arguments provided to this program.
    */
 
   public static void main(String[] args)
   {
-    int retCode =
-        mainSearchRate(args, System.in, System.out, System.err);
+    int retCode = mainSearchRate(args, System.in, System.out,
+        System.err);
 
     if (retCode != 0)
     {
@@ -81,7 +83,7 @@
   /**
    * Parses the provided command-line arguments and uses that
    * information to run the ldapsearch tool.
-   * 
+   *
    * @param args
    *          The command-line arguments provided to this program.
    * @return The error code.
@@ -97,7 +99,7 @@
   /**
    * Parses the provided command-line arguments and uses that
    * information to run the ldapsearch tool.
-   * 
+   *
    * @param args
    *          The command-line arguments provided to this program.
    * @param inStream
@@ -133,13 +135,13 @@
   {
     // Create the command-line argument parser for use with this
     // program.
-    Message toolDescription =
-        Message.raw("This utility can be used to "
+    Message toolDescription = Message
+        .raw("This utility can be used to "
             + "measure search performance");
     // TODO: correct usage
-    ArgumentParser argParser =
-        new ArgumentParser(SearchRate.class.getName(), toolDescription,
-            false, true, 1, 0, "[filter] [attributes ...]");
+    ArgumentParser argParser = new ArgumentParser(SearchRate.class
+        .getName(), toolDescription, false, true, 1, 0,
+        "[filter] [attributes ...]");
 
     ArgumentParserConnectionFactory connectionFactory;
     SearchPerformanceRunner runner;
@@ -153,61 +155,54 @@
 
     try
     {
-      connectionFactory =
-          new ArgumentParserConnectionFactory(argParser, this);
+      connectionFactory = new ArgumentParserConnectionFactory(
+          argParser, this);
       runner = new SearchPerformanceRunner(argParser, this);
 
-      propertiesFileArgument =
-          new StringArgument("propertiesFilePath", null,
-              OPTION_LONG_PROP_FILE_PATH, false, false, true,
-              INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
-              INFO_DESCRIPTION_PROP_FILE_PATH.get());
+      propertiesFileArgument = new StringArgument("propertiesFilePath",
+          null, OPTION_LONG_PROP_FILE_PATH, false, false, true,
+          INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null,
+          INFO_DESCRIPTION_PROP_FILE_PATH.get());
       argParser.addArgument(propertiesFileArgument);
       argParser.setFilePropertiesArgument(propertiesFileArgument);
 
-      noPropertiesFileArgument =
-          new BooleanArgument("noPropertiesFileArgument", null,
-              OPTION_LONG_NO_PROP_FILE, INFO_DESCRIPTION_NO_PROP_FILE
-                  .get());
+      noPropertiesFileArgument = new BooleanArgument(
+          "noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE,
+          INFO_DESCRIPTION_NO_PROP_FILE.get());
       argParser.addArgument(noPropertiesFileArgument);
       argParser.setNoPropertiesFileArgument(noPropertiesFileArgument);
 
-      showUsage =
-          new BooleanArgument("showUsage", OPTION_SHORT_HELP,
-              OPTION_LONG_HELP, INFO_DESCRIPTION_SHOWUSAGE.get());
+      showUsage = new BooleanArgument("showUsage", OPTION_SHORT_HELP,
+          OPTION_LONG_HELP, INFO_DESCRIPTION_SHOWUSAGE.get());
       argParser.addArgument(showUsage);
       argParser.setUsageArgument(showUsage, getOutputStream());
 
-      baseDN =
-          new StringArgument("baseDN", OPTION_SHORT_BASEDN,
-              OPTION_LONG_BASEDN, true, false, true,
-              INFO_BASEDN_PLACEHOLDER.get(), null, null,
-              INFO_SEARCH_DESCRIPTION_BASEDN.get());
+      baseDN = new StringArgument("baseDN", OPTION_SHORT_BASEDN,
+          OPTION_LONG_BASEDN, true, false, true,
+          INFO_BASEDN_PLACEHOLDER.get(), null, null,
+          INFO_SEARCH_DESCRIPTION_BASEDN.get());
       baseDN.setPropertyName(OPTION_LONG_BASEDN);
       argParser.addArgument(baseDN);
 
-      searchScope =
-          new MultiChoiceArgument<SearchScope>("searchScope", 's',
-              "searchScope", false, true, INFO_SEARCH_SCOPE_PLACEHOLDER
-                  .get(), SearchScope.values(), false,
-              INFO_SEARCH_DESCRIPTION_SEARCH_SCOPE.get());
+      searchScope = new MultiChoiceArgument<SearchScope>("searchScope",
+          's', "searchScope", false, true,
+          INFO_SEARCH_SCOPE_PLACEHOLDER.get(), SearchScope.values(),
+          false, INFO_SEARCH_DESCRIPTION_SEARCH_SCOPE.get());
       searchScope.setPropertyName("searchScope");
       searchScope.setDefaultValue(SearchScope.WHOLE_SUBTREE);
       argParser.addArgument(searchScope);
 
-      dereferencePolicy =
-          new MultiChoiceArgument<DereferenceAliasesPolicy>(
-              "derefpolicy", 'a', "dereferencePolicy", false, true,
-              INFO_DEREFERENCE_POLICE_PLACEHOLDER.get(),
-              DereferenceAliasesPolicy.values(), false,
-              INFO_SEARCH_DESCRIPTION_DEREFERENCE_POLICY.get());
+      dereferencePolicy = new MultiChoiceArgument<DereferenceAliasesPolicy>(
+          "derefpolicy", 'a', "dereferencePolicy", false, true,
+          INFO_DEREFERENCE_POLICE_PLACEHOLDER.get(),
+          DereferenceAliasesPolicy.values(), false,
+          INFO_SEARCH_DESCRIPTION_DEREFERENCE_POLICY.get());
       dereferencePolicy.setPropertyName("dereferencePolicy");
       dereferencePolicy.setDefaultValue(DereferenceAliasesPolicy.NEVER);
       argParser.addArgument(dereferencePolicy);
 
-      verbose =
-          new BooleanArgument("verbose", 'v', "verbose",
-              INFO_DESCRIPTION_VERBOSE.get());
+      verbose = new BooleanArgument("verbose", 'v', "verbose",
+          INFO_DESCRIPTION_VERBOSE.get());
       verbose.setPropertyName("verbose");
       argParser.addArgument(verbose);
     }
@@ -241,8 +236,8 @@
     }
 
     List<String> attributes = new LinkedList<String>();
-    ArrayList<String> filterAndAttributeStrings =
-        argParser.getTrailingArguments();
+    ArrayList<String> filterAndAttributeStrings = argParser
+        .getTrailingArguments();
     if (filterAndAttributeStrings.size() > 0)
     {
       // the list of trailing arguments should be structured as follow:
@@ -255,14 +250,14 @@
         attributes.add(s);
       }
     }
-    runner.attributes =
-        attributes.toArray(new String[attributes.size()]);
+    runner.attributes = attributes
+        .toArray(new String[attributes.size()]);
     runner.baseDN = baseDN.getValue();
     try
     {
       runner.scope = searchScope.getTypedValue();
-      runner.dereferencesAliasesPolicy =
-          dereferencePolicy.getTypedValue();
+      runner.dereferencesAliasesPolicy = dereferencePolicy
+          .getTypedValue();
     }
     catch (ArgumentException ex1)
     {
@@ -274,8 +269,8 @@
     {
       // Try it out to make sure the format string and data sources
       // match.
-      Object[] data =
-          DataSource.generateData(runner.getDataSources(), null);
+      Object[] data = DataSource.generateData(runner.getDataSources(),
+          null);
       String.format(runner.filter, data);
       String.format(runner.baseDN, data);
     }
@@ -289,6 +284,8 @@
     return runner.run(connectionFactory);
   }
 
+
+
   private final AtomicInteger entryRecentCount = new AtomicInteger();
 
 
@@ -296,9 +293,13 @@
   private class SearchPerformanceRunner extends PerformanceRunner
   {
     private String filter;
+
     private String baseDN;
+
     private SearchScope scope;
+
     private DereferenceAliasesPolicy dereferencesAliasesPolicy;
+
     private String[] attributes;
 
 
@@ -356,6 +357,7 @@
         WorkerThread<SearchStatsHandler>
     {
       private SearchRequest sr;
+
       private Object[] data;
 
 
@@ -389,9 +391,8 @@
           else
           {
             data = DataSource.generateData(dataSources, data);
-            sr =
-                Requests.newSearchRequest(String.format(baseDN, data), scope,
-                    String.format(filter, data), attributes);
+            sr = Requests.newSearchRequest(String.format(baseDN, data),
+                scope, String.format(filter, data), attributes);
           }
           sr.setDereferenceAliasesPolicy(dereferencesAliasesPolicy);
         }
@@ -410,6 +411,7 @@
     private class SearchStatsThread extends StatsThread
     {
       private long totalEntryCount;
+
       private final String[] extraColumn;
 
 
@@ -426,8 +428,8 @@
       {
         int entryCount = entryRecentCount.getAndSet(0);
         totalEntryCount += entryCount;
-        extraColumn[0] =
-            String.format("%.1f", (double) entryCount / successCount);
+        extraColumn[0] = String.format("%.1f", (double) entryCount
+            / successCount);
         return extraColumn;
       }
     }
@@ -437,7 +439,7 @@
 
   /**
    * Indicates whether or not the user has requested advanced mode.
-   * 
+   *
    * @return Returns <code>true</code> if the user has requested
    *         advanced mode.
    */
@@ -451,7 +453,7 @@
   /**
    * Indicates whether or not the user has requested interactive
    * behavior.
-   * 
+   *
    * @return Returns <code>true</code> if the user has requested
    *         interactive behavior.
    */
@@ -468,7 +470,7 @@
    * go to the error stream or not. In addition, it may also dictate
    * whether or not sub-menus should display a cancel option as well as
    * a quit option.
-   * 
+   *
    * @return Returns <code>true</code> if this console application is
    *         running in its menu-driven mode.
    */
@@ -481,7 +483,7 @@
 
   /**
    * Indicates whether or not the user has requested quiet output.
-   * 
+   *
    * @return Returns <code>true</code> if the user has requested quiet
    *         output.
    */
@@ -495,7 +497,7 @@
   /**
    * Indicates whether or not the user has requested script-friendly
    * output.
-   * 
+   *
    * @return Returns <code>true</code> if the user has requested
    *         script-friendly output.
    */
@@ -508,7 +510,7 @@
 
   /**
    * Indicates whether or not the user has requested verbose output.
-   * 
+   *
    * @return Returns <code>true</code> if the user has requested verbose
    *         output.
    */

--
Gitblit v1.10.0