/** * This method should setup the flags/switches for the java command which will determine the * actual command to be executed. * * <p>Sets up flags like : * * <ul> * <li>-Dem.home * <li>-Dprocess.name * </ul> * * <br> * add computes the classpath. */ protected void updateFlags(ServerCommand serverCmd) { String bootDir = System.getProperty("em.home"); String appType = System.getProperty("appType"); String appInst = System.getProperty("appInst"); String javaClasspath = serverCmd.getClasspath(); String processName = getProcessNameForLog(); List jvmFlags = serverCmd.getJVMFlags(); int cpToken = -1; for (int i = 0; i < jvmFlags.size(); i++) { String token = (String) jvmFlags.get(i); if (token.startsWith("-classpath")) { cpToken = i; javaClasspath = null; } else if (token.startsWith("-Dem.home")) { bootDir = null; } else if (token.startsWith("-Dprocess.name")) { processName = null; } } List addonJVMFlags = new LinkedList(); if (bootDir != null) { addonJVMFlags.add("-Dem.home=" + bootDir); } if (processName != null) { addonJVMFlags.add("-Dprocess.name=" + processName); } if (!(appType == null || appType.trim().equals(""))) { addonJVMFlags.add("-DappType=" + appType); } if (!(appInst == null || appInst.trim().equals(""))) { addonJVMFlags.add("-DappInst=" + appInst); } if (cpToken != -1) { jvmFlags.remove(cpToken); String str = (String) jvmFlags.remove(cpToken); serverCmd.setClasspath(str); } jvmFlags.addAll(addonJVMFlags); }
/** * 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); }
/** * Look at the various property settings and create the command line for this server. * * @return the command line for this server. */ protected List buildExecCommand() { try { String cmd = getCommand(); if (cmd == null) { return null; } mLogger.finest(LogUtil.splitLine(cmd)); // Get java specific properties LinkedList execTokens = tokenizeCommand(cmd); String firstToken = (String) execTokens.get(0); if (firstToken.equals("java")) { // This is a java command, so rework it if (execTokens.size() < 2) { return null; } mIsJavaServer = true; List props = new LinkedList(); props.add(mPropertyPrefix + ".nativeLogging"); props.add(WDConstants.WD_PREFIX + ".nativeLogging"); String nativeLog = getProperty(props); if (nativeLog == null || nativeLog.equals("false")) { setNativeLoggingUsed(false); } else { setNativeLoggingUsed(true); } String mainClassName = (String) execTokens.getLast(); List cmdLineFlags = null; if (execTokens.size() > 2) { cmdLineFlags = execTokens.subList(1, execTokens.size() - 1); } String javaClasspath = getJavaClasspath(); String addCp = getJavaAdditionalClasspath(); if (addCp != null) { javaClasspath += File.pathSeparator + addCp; } String jvm = getJavaJVM(); String jvmType = getJVMType(); List jvmFlags = getJVMFlags(); List appArgs = getAppArgs(); mServerCmd = new ServerCommand( jvm, jvmType, jvmFlags, javaClasspath, mainClassName, cmdLineFlags, appArgs); updateFlags(mServerCmd); updateServerCommandForSpecialHandling(mServerCmd); execTokens = mServerCmd.getTokens(); mLogger.finest(LogUtil.splitLine(execTokens.toString())); } else { setNativeLoggingUsed(true); } return execTokens; } catch (Exception e) { mLogger.severe("Failed to buildExecCmd", e); return null; } }