/** Prints information about the agent configuration options */
  public void configHelp() {
    PrintStream out = System.out;

    Properties props = AgentConfigImpl.getDefaultValuesForAllProperties();

    out.println("\n");
    out.println(LocalizedStrings.AgentLauncher_AGENT_CONFIGURATION_PROPERTIES.toString());

    SortedMap<String, String> map = new TreeMap<String, String>();

    int maxLength = 0;
    for (Iterator<Object> iter = props.keySet().iterator(); iter.hasNext(); ) {
      String prop = (String) iter.next();
      int length = prop.length();
      if (length > maxLength) {
        maxLength = length;
      }

      map.put(
          prop,
          AgentConfigImpl.getPropertyDescription(prop)
              + " ("
              + LocalizedStrings.AgentLauncher_DEFAULT.toLocalizedString()
              + "  \""
              + props.getProperty(prop)
              + "\")");
    }

    Iterator<Entry<String, String>> entries = map.entrySet().iterator();
    while (entries.hasNext()) {
      Entry<String, String> entry = entries.next();
      String prop = entry.getKey();
      out.print("  ");
      out.println(prop);

      String description = entry.getValue();
      StringTokenizer st = new StringTokenizer(description, " ");
      out.print("    ");
      int printed = 6;
      while (st.hasMoreTokens()) {
        String word = st.nextToken();
        if (printed + word.length() > 72) {
          out.print("\n    ");
          printed = 6;
        }
        out.print(word);
        out.print(" ");
        printed += word.length() + 1;
      }
      out.println("");
    }
    out.println("");

    System.exit(1);
  }
  private Agent createAgent(final Properties props) throws IOException, AdminException {
    DistributionManager.isDedicatedAdminVM = true;
    SystemFailure.setExitOK(true);

    final AgentConfigImpl config = createAgentConfig(props);

    // see bug 43760
    if (config.getLogFile() == null || "".equals(config.getLogFile().trim())) {
      config.setLogFile(AgentConfigImpl.DEFAULT_LOG_FILE);
    }

    logger = config.getLogWriter();
    OSProcess.redirectOutput(
        new File(config.getLogFile())); // redirect output to the configured log file

    return AgentFactory.getAgent(config);
  }
  /**
   * Returns a map that maps the name of the start options to its value on the command line. If no
   * value is specified on the command line, a default one is provided.
   */
  protected Map<String, Object> getStartOptions(final String[] args) throws Exception {
    final Map<String, Object> options = new HashMap<String, Object>();

    options.put(APPENDTO_LOG_FILE, "false");
    options.put(DIR, IOUtils.tryGetCanonicalFileElseGetAbsoluteFile(new File(".")));

    final List<String> vmArgs = new ArrayList<String>();
    options.put(VMARGS, vmArgs);

    final Properties agentProps = new Properties();
    options.put(AGENT_PROPS, agentProps);

    final Map<String, String> envArgs = new HashMap<String, String>();
    options.put(ENVARGS, envArgs);

    for (final String arg : args) {
      if (arg.startsWith("-classpath=")) {
        options.put(CLASSPATH, arg.substring("-classpath=".length()));
      } else if (arg.startsWith("-dir=")) {
        final File workingDirectory = processDirOption(options, arg.substring("-dir=".length()));
        System.setProperty(
            AgentConfigImpl.AGENT_PROPSFILE_PROPERTY_NAME,
            new File(workingDirectory, AgentConfig.DEFAULT_PROPERTY_FILE).getPath());
      } else if (arg.startsWith("-J")) {
        vmArgs.add(arg.substring(2));
      } else if (arg.contains("=")) {
        final int index = arg.indexOf("=");
        final String key = arg.substring(0, index);
        final String value = arg.substring(index + 1);

        if (key.startsWith("-")) {
          processStartOption(key.substring(1), value, options, vmArgs, envArgs, agentProps);
        } else {
          // if appendto-log-file is set, put it in options; it is not set as an
          // agent prop
          if (key.equals(APPENDTO_LOG_FILE)) {
            options.put(APPENDTO_LOG_FILE, value);
            continue;
          }

          // verify the property is valid
          AgentConfigImpl.getPropertyDescription(key);

          // Note, the gfAgentPropertyFile System property is ultimately read
          // in the constructor of the AgentImpl class in order to make any
          // properties defined in this file not only accessible to the
          // DistributedSystem but to the GemFire Agent as well.
          if (key.equals(AgentConfigImpl.PROPERTY_FILE_NAME)) {
            System.setProperty(AgentConfigImpl.AGENT_PROPSFILE_PROPERTY_NAME, value);
          }

          // The Agent properties file (specified with the command-line
          //   key=value) is used to pass configuration settings to the GemFire
          // DistributedSystem. A property file can be passed using the
          // property-file command-line switch is a large number of properties
          // are specified, or the properties maybe individually specified on
          // the command-line as property=value arguments.
          processStartArg(key, value, options, vmArgs, agentProps);
        }
      } else if (arg.equalsIgnoreCase("-password")) {
        processStartOption(arg.substring(1), null, options, vmArgs, envArgs, agentProps);
      }
    }

    return options;
  }