示例#1
0
  /**
   * This method should update the ServerCommand "struct" and setup the necessary values for the
   * server to be executed under OptimizeIt.
   */
  protected void updateServerCommandForOptimizeIt(ServerCommand serverCmd) {

    mLogger.config(mPropertyPrefix + " checking for optit");

    String optitPrefix = WDConstants.WD_PREFIX + ".java.profilers.OptimizeIt.";

    String home = DCPLib.getProperty(optitPrefix + "home", null);
    if (home == null) {
      mLogger.warning("OptimizeItHome is not specified. Cannot start OptimizeIt");
      return;
    }

    if (!(new java.io.File(home)).exists()) {
      mLogger.warning("OptimizeItHome : " + home + " does not exist." + " Cannot start OptimizeIt");
      return;
    }

    String classPath = DCPLib.getProperty(optitPrefix + "addonClassPath", "");
    classPath = WDUtil.sreplace(classPath, "OPTIMIZEIT_HOME", home);
    serverCmd.setClasspath(serverCmd.getClasspath() + File.pathSeparator + classPath);

    String libPath = DCPLib.getProperty(optitPrefix + "addonLibPath", "");
    libPath = WDUtil.sreplace(libPath, "OPTIMIZEIT_HOME", home);

    String sysLibPath = serverCmd.getLibPath();
    if (sysLibPath == null) sysLibPath = System.getProperty("java.library.path", "");
    serverCmd.setLibPath(libPath + File.pathSeparator + sysLibPath);

    String javaArgs = DCPLib.getProperty(optitPrefix + "javaArgs", "");
    javaArgs = WDUtil.sreplace(javaArgs, "OPTIMIZEIT_HOME", home);
    List jvmFlags = serverCmd.getJVMFlags();
    jvmFlags.add(0, javaArgs);

    String profilerClass = DCPLib.getProperty(optitPrefix + "class", "intuitive.audit.Audit");

    if (mOptitAuditPort == null) {
      mOptitAuditPort = getOptimizeItAuditPort(mPropertyPrefix);
    }
    System.out.println("OptimizeIt for " + mName + " is running at " + mOptitAuditPort);
    mLogger.config("OptimizeIt running at " + mOptitAuditPort);

    String optitArgs = DCPLib.getProperty(optitPrefix + "args", "");
    optitArgs = WDUtil.sreplace(optitArgs, "OPTIMIZEIT_HOME", home);
    optitArgs = WDUtil.sreplace(optitArgs, "AUDIT_PORT", mOptitAuditPort);

    String mainClass = serverCmd.getMainClassName();
    List appArgs = serverCmd.getAppArgs();

    serverCmd.setMainClassName(profilerClass);

    appArgs.add(0, mainClass);
    appArgs.add(0, optitArgs);
  }
示例#2
0
  /**
   * Return the java debugger flags. If useJDB is true for this server, then this method updates the
   * debug port in watchdog.java.debug.flags and returns the resultant flags.
   */
  protected String getJVMDebugFlags() {
    if (useJDB()) {

      String port = getDebugPort();
      System.out.println(mName + " Java debug port is : " + port);
      mLogger.config("Java debug port is : " + port);

      String dflags = getProperty(WDConstants.WD_PREFIX + ".java.debug.flags");
      if (dflags == null) return "";
      dflags = WDUtil.sreplace(dflags, "PORT", port);
      return dflags;
    }
    return "";
  }
示例#3
0
  /**
   * Tokenizes a command string into a list.
   *
   * @throws Exception if the command cannot be tokenized
   */
  protected static LinkedList _tokenizeCommand(String cmd) throws Exception {

    LinkedList tokens = new LinkedList();
    int startIndex = 0;
    int dQuoteAt = cmd.indexOf('"');
    int sQuoteAt = cmd.indexOf('\'');

    if (dQuoteAt == -1 && sQuoteAt == -1) {
      StringTokenizer st = new StringTokenizer(cmd.trim());
      while (st.hasMoreTokens()) {
        tokens.add(st.nextToken());
      }
      return tokens;
    }

    char[] chArray = cmd.trim().toCharArray();

    int endIndex = 0;
    boolean inQuotes = false;
    char c = 0;
    char lastc = 0;
    char lastqc = 0;
    StringBuffer sb = new StringBuffer(80);

    while (endIndex < chArray.length) {
      c = chArray[endIndex];
      if (!Character.isWhitespace(c)) {
        if (c == '"' || c == '\'') {
          if (inQuotes && lastc != '\\' && lastqc == c) {
            tokens.add(sb.toString());
            inQuotes = false;
            sb.setLength(0);
          } else if (!inQuotes) {
            inQuotes = true;
            lastqc = c;
          } else {
            sb.append(c);
          }
        } else if (c == '\\') {
          if (lastc == '\\') sb.append(c);
        } else {
          sb.append(c);
        }
      } else {
        if (inQuotes) {
          sb.append(c);
        } else {
          if (sb.length() > 0) {
            tokens.add(sb.toString());
            sb.setLength(0);
          }
        }
      }
      lastc = c;
      ++endIndex;
    }

    if (inQuotes) {
      throw new Exception(
          WDExUtil.formatMessage(WDExConstants.UNTERMINATED_STRING, WDUtil.toArray(cmd)));
    }
    return tokens;
  }