alma::acs::testsupport::ProcessUtil Class Reference

Collaboration diagram for alma::acs::testsupport::ProcessUtil:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

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!


Constructor & Destructor Documentation

alma::acs::testsupport::ProcessUtil::ProcessUtil ( Logger  logger  )  [inline]

Member Function Documentation

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.

Returns:
Map<classname, pid-list>
Exceptions:
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.

Exceptions:
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.

Exceptions:
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.

Parameters:
tough if true, a tough way of killing is used (kill -9)
Returns:
Exit value of the kill command
Exceptions:
IOException 
InterruptedException 

References logger.

Referenced by alma::acs::testsupport::ProcessUtilTest::testJava().

void alma::acs::testsupport::ProcessUtil::setDebug ( boolean  DEBUG  )  [inline]

Member Data Documentation

volatile boolean alma::acs::testsupport::ProcessUtil::DEBUG = false [private]

Referenced by getJavaPIDs().

Referenced by getJavaPIDs(), and killProcess().


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2