/** * 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); }
/** * Looks for properties "watchdog.server.<SERVER_NAME>.java.vmtype" followed by * "watchdog.java.vmtype" in the configuration and returns the first non-null value. If both are * not available, returns null. */ protected String getJVMType() { List queue = new LinkedList(); queue.add(mPropertyPrefix + ".java.vmtype"); queue.add(WDConstants.WD_PREFIX + ".java.vmtype"); String vmType = getProperty(queue); return vmType; }
protected void prepare() throws Exception { try { List execCommand = buildExecCommand(); if (execCommand == null) { mLogger.severe("No command property was specified; disabling server"); synchronized (this) { changeState(STATE_DISABLED); } return; } else { mExecArgs = (String[]) execCommand.toArray(new String[0]); StringBuffer printableCmd = new StringBuffer(4096); int index = 0; for (; index < mExecArgs.length - 1; index++) { printableCmd.append(mExecArgs[index]).append(" "); } printableCmd.append(mExecArgs[index]); mPrintableCommand = printableCmd.toString(); if (useOptimizeIt()) { System.err.println(mPrintableCommand); } } } catch (Exception ex) { mLogger.severe("Failed In preparing execargs"); throw ex; } }
/** * Looks for properties "watchdog.server.<SERVER_NAME>.java.home" followed by * "watchdog.java.home" in the configuration and returns the first non-null value. If both are not * available, returns the "java.home" system property. */ protected String getJavaHome() { List queue = new LinkedList(); queue.add(mPropertyPrefix + ".java.home"); queue.add(WDConstants.WD_PREFIX + ".java.home"); String javaHome = getProperty(queue); if (javaHome == null) javaHome = System.getProperty("java.home"); return javaHome; }
/** * Looks for properties "watchdog.server.<SERVER_NAME>.java.class.path" followed by * "watchdog.java.class.path" in the configuration and returns the first non-null value. If both * are not available, returns the "java.class.path" system property. */ protected String getJavaClasspath() { List queue = new LinkedList(); queue.add(mPropertyPrefix + ".java.class.path"); queue.add(WDConstants.WD_PREFIX + ".java.class.path"); String cpath = getProperty(queue); if (cpath == null) { cpath = System.getProperty("java.class.path"); } return cpath; }
/** * 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); }
/** * Looks for properties "watchdog.server.<SERVER_NAME>.java.jvm" followed by * "watchdog.java.jvm" in the configuration and returns the first non-null value. If both are not * available, returns the /bin/java in the directory returned by getJavaHome * * @see ProcessExecutor#getJavaHome */ protected String getJavaJVM() { List queue = new LinkedList(); queue.add(mPropertyPrefix + ".java.jvm"); queue.add(WDConstants.WD_PREFIX + ".java.jvm"); String javaVM = getProperty(queue); if (javaVM == null) { String fileSeparator = System.getProperty("file.separator"); String javaHome = getJavaHome(); javaVM = javaHome + fileSeparator + "bin" + fileSeparator + "java"; } return javaVM; }
/** * 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; } }
/** * Looks for properties "watchdog.server.<SERVER_NAME>.java.cp" followed by * "watchdog.java.cp" in the configuration and returns the first non-null value. If both are null, * returns null. */ protected String getJavaAdditionalClasspath() { List queue = new LinkedList(); queue.add(mPropertyPrefix + ".java.cp"); queue.add(WDConstants.WD_PREFIX + ".java.cp"); return getProperty(queue); }