public AS7CommandLine(ProcessInfo process) { this(process.getCommandLine()); this.process = process; }
protected String getSystemPropertyValue(ProcessInfo process, String systemPropertyName) { for (String argument : process.getCommandLine()) { String prefix = "-D" + systemPropertyName + "="; if (argument.startsWith(prefix)) { return argument.substring(prefix.length()); } } return null; }
protected String getJavaMainClassName(ProcessInfo process) { // TODO (ips, 04/02/12): If command line contains "-jar foo.jar", pull the main class name out of foo.jar's // MANIFEST.MF. String className = null; for (int i = 1; i < process.getCommandLine().length; i++) { String arg = process.getCommandLine()[i]; if (!arg.startsWith("-")) { className = arg; break; } else if (arg.equals("-cp") || arg.equals("-classpath")) { // The next arg is the classpath - skip it. i++; } } return className; }
protected String getJavaVersion(ProcessInfo process, JMXServiceURL jmxServiceURL) { JMXConnector jmxConnector = null; try { jmxConnector = connect(jmxServiceURL); return getJavaVersion(jmxConnector); } catch (SecurityException e) { log.warn("Unable to to authenticate to JMX service URL [" + jmxServiceURL + "]: " + e.getMessage()); } catch (IOException e) { log.error("Failed to connect to JMX service URL [" + jmxServiceURL + "].", e); } catch (Exception e) { log.error("Failed to determine JVM version for process [" + process.getPid() + "] with command line [" + Arrays.asList(process.getCommandLine()) + "].", e); } finally { close(jmxConnector); } // TODO: We could exec "java -version" here. return null; }
private List<ProcessScanResult> getNonExcludedJavaProcesses(ResourceDiscoveryContext context) { // This is the list of all currently running java processes. List<ProcessScanResult> javaProcesses = context.getAutoDiscoveredProcesses(); List<ProcessScanResult> nonExcludedJavaProcesses = new ArrayList<ProcessScanResult>(); Set<String> processExcludes = getProcessExcludes(); for (ProcessScanResult javaProcess : javaProcesses) { String[] args = javaProcess.getProcessInfo().getCommandLine(); StringBuilder buffer = new StringBuilder(); for (String arg : args) { buffer.append(arg).append(" "); } String commandLine = buffer.toString(); if (!isExcluded(commandLine, processExcludes)) { nonExcludedJavaProcesses.add(javaProcess); } else { if (log.isDebugEnabled()) { log.debug("Process [" + javaProcess.getProcessInfo() + "] excluded since its command line contains one of the following: " + processExcludes); } } } return nonExcludedJavaProcesses; }
private JvmResourceKey buildResourceKey(ProcessInfo process, Integer jmxRemotingPort) { JvmResourceKey key; String mainClassName = getJavaMainClassName(process); String keyString = getSystemPropertyValue(process, SYSPROP_RHQ_RESOURCE_KEY); if (keyString != null && !keyString.equals("")) { log.debug("Using explicitly specified Resource key: [" + keyString + "]..."); key = JvmResourceKey.fromExplicitValue(mainClassName, keyString); } else { if (jmxRemotingPort != null) { log.debug("Using JMX remoting port [" + jmxRemotingPort + "] as Resource key..."); key = JvmResourceKey.fromJmxRemotingPort(mainClassName, jmxRemotingPort); } else { log.debug("Process [" + process.getPid() + "] with command line [" + Arrays.asList(process.getCommandLine()) + "] cannot be discovered, because it does not specify either of the following system properties: " + "-D" + SYSPROP_JMXREMOTE_PORT + "=12345, -D" + SYSPROP_RHQ_RESOURCE_KEY + "=UNIQUE_KEY"); key = null; } } return key; }
String[] serverParentProcessCommandLine = serverParentProcess.getCommandLine(); Integer startScriptIndex = getStartScriptIndex(serverParentProcessCommandLine);
public static List<String> getStartScriptArgs(ProcessInfo serverParentProcess, List<String> serverArgs, Set<CommandLineOption> optionExcludes) { String[] startScriptCommandLine = serverParentProcess.getCommandLine(); Integer startScriptIndex = getStartScriptIndex(startScriptCommandLine);
String[] cmdline = (processToMatch != null) ? processToMatch.getCommandLine() : null;
String[] cmdline = (processToMatch != null) ? processToMatch.getCommandLine() : null;
String[] commandLine = processInfo.getCommandLine();