
Public Member Functions | |
| ProcessUtil (Logger logger) | |
| List< String > | getJavaPIDs (Class<?> mainClass) throws IOException |
| boolean | isJavaProcessRunning (Class<?> mainClass) throws IOException |
| int | killProcess (String pid, boolean tough) throws IOException, InterruptedException |
| void | setDebug (boolean DEBUG) |
Protected Member Functions | |
| Map< String, List< String > > | getJavaPIDs () throws IOException |
Private Attributes | |
| final Logger | logger |
| volatile boolean | DEBUG = false |
Helper class to be used by tests which need to verify that some other process exists or does not exist, or that need to kill some process. Don't use this class in operational code!
| alma::acs::testsupport::ProcessUtil::ProcessUtil | ( | Logger | logger | ) | [inline] |
| Map<String, List<String> > alma::acs::testsupport::ProcessUtil::getJavaPIDs | ( | ) | throws IOException [inline, protected] |
Gets a map with key=(running java main classes) and value=(list of the process IDs). Filters out sun.tools.jps.Jps which is the tool used to get the processes.
| IOException | ||
| InterruptedException |
References DEBUG, alma::acs::util::ProcessStreamGobbler::getStdout(), alma::acs::util::ProcessStreamGobbler::gobble(), alma::acs::util::ProcessStreamGobbler::hasStreamReadErrors(), logger, and alma::acs::util::ProcessStreamGobbler::setDebug().
Referenced by getJavaPIDs(), and isJavaProcessRunning().
| List<String> alma::acs::testsupport::ProcessUtil::getJavaPIDs | ( | Class<?> | mainClass | ) | throws IOException [inline] |
Gets the process IDs of all java processes run by the current user on the local host, whose main class is given as the parameter.
The "jps" command is used via Runtime.exec, which should work not only on Linux but also on Windows.
| IOException |
References getJavaPIDs().
Referenced by alma::acs::testsupport::ProcessUtilTest::testJava().
| boolean alma::acs::testsupport::ProcessUtil::isJavaProcessRunning | ( | Class<?> | mainClass | ) | throws IOException [inline] |
Returns true if one or more JVMs are running the given Java main class on the local host as the current user.
| IOException |
References getJavaPIDs().
Referenced by alma::acs::testsupport::ProcessUtilTest::testJava().
| int alma::acs::testsupport::ProcessUtil::killProcess | ( | String | pid, | |
| boolean | tough | |||
| ) | throws IOException, InterruptedException [inline] |
Kills a process with a given PID, which could be obtained from getJavaPIDs(Class).
Currently this method works only on Linux because it uses the "kill -9" command.
Currently the stdout and stderr from running "kill" are not gobbled because they are expected to be very small and thus won't block buffers etc. If they do, then use ProcessStreamGobbler also here.
| tough | if true, a tough way of killing is used (kill -9) |
| IOException | ||
| InterruptedException |
References logger.
Referenced by alma::acs::testsupport::ProcessUtilTest::testJava().
| void alma::acs::testsupport::ProcessUtil::setDebug | ( | boolean | DEBUG | ) | [inline] |
Referenced by alma::acs::testsupport::ProcessUtilTest::setUp().
volatile boolean alma::acs::testsupport::ProcessUtil::DEBUG = false [private] |
Referenced by getJavaPIDs().
final Logger alma::acs::testsupport::ProcessUtil::logger [private] |
Referenced by getJavaPIDs(), and killProcess().
1.6.2