|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||

java.lang.Objectcz.cuni.amis.utils.process.ProcessExecution
public class ProcessExecution
Class that wrapps the execution of the arbitrary process that is configured by ProcessExecutionConfig.
The class is not suitable for inheritance ... better copy-paste and adjust for yourself.
| Field Summary | |
|---|---|
protected ProcessExecutionConfig |
config
Configuration of the process to run. |
static Pattern |
FORMAL_PARAM
|
protected Logger |
log
Log used by the object, specified during the construction. |
protected Process |
process
When start()ed it contains the process. |
protected cz.cuni.amis.utils.flag.Flag<Boolean> |
running
Flag whether the process is running, we're synchronizing access to this class on this flag. |
protected Runnable |
shutDownHook
Task that will kill the process when user forgets to do so before the JVM is killed. |
protected Thread |
shutDownHookThread
|
static Pattern |
SIMPLE_PARAM
|
protected cz.cuni.amis.utils.StreamSink |
streamSinkError
Sink for the STDERR of the process, it may be redirected to log. |
protected cz.cuni.amis.utils.StreamSink |
streamSinkOutput
Sink for the STDOUT of the process, it may be redirected to log. |
protected boolean |
timedout
Whether the process timed out or not. |
protected Runnable |
waitForEnd
Task that is waiting for the end of the process to switch running back to false
and shutdown all other utility threads (like sink). |
protected Thread |
waitForEndThread
|
| Constructor Summary | |
|---|---|
ProcessExecution(ProcessExecutionConfig config,
Logger log)
|
|
| Method Summary | |
|---|---|
Process |
getBotProcess()
Process of the process (non-null if started). |
Integer |
getExitValue()
Returns exit value of the process. |
cz.cuni.amis.utils.flag.ImmutableFlag<Boolean> |
getRunning()
Flag of the state of the process. |
boolean |
isFailed()
Tells whether the process has failed == timed out / exit value is not 0. |
boolean |
isFailed(boolean report)
Tells whether the process has failed == timed out / exit value is not 0. |
boolean |
isRunning()
Flag of the state of the process. |
boolean |
isTimeout()
If ProcessExecutionConfig.getTimeout() is specified, this will indicate whether the started process has
timed out or not. |
protected void |
shutdown(boolean waitForEndThread)
Shutdowns the process and cleans-up everything, preparing the object to be start()ed again. |
void |
start()
Start the process. |
void |
stop()
Shuts down the process (if it is running, otherwise does nothing). |
static String |
substituteParams(String command,
Logger log)
Searches for $XXX or ${XXX} and substitute them with System.getenv() (prioritized) or System.getProperty(String). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected ProcessExecutionConfig config
protected cz.cuni.amis.utils.flag.Flag<Boolean> running
Set to TRUE ONLY IN start() and back to FALSE ONLY IN shutdown(boolean).
Do not alter the flag from anywhere else!
protected Process process
start()ed it contains the process.
protected cz.cuni.amis.utils.StreamSink streamSinkOutput
log.
protected cz.cuni.amis.utils.StreamSink streamSinkError
log.
protected Logger log
protected Runnable shutDownHook
protected Thread shutDownHookThread
protected boolean timedout
protected Runnable waitForEnd
running back to false
and shutdown all other utility threads (like sink).
protected Thread waitForEndThread
public static final Pattern SIMPLE_PARAM
public static final Pattern FORMAL_PARAM
| Constructor Detail |
|---|
public ProcessExecution(ProcessExecutionConfig config,
Logger log)
config - process execution configuration (contains path to file to run)log - log to be used (stdout/stderr of the process will be redirected there as well with Level.INFO)| Method Detail |
|---|
public static String substituteParams(String command,
Logger log)
System.getenv() (prioritized) or System.getProperty(String).
command -
public void start()
throws cz.cuni.amis.utils.exception.PogamutIOException
PogamutIOException if it fails to start the JVM.
It is wise to observe the state of the getRunning() flag to obtain the state of the process
(whether the process is running or is dead). Usage of FlagListener is advised, see ImmutableFlag.addListener(FlagListener).
cz.cuni.amis.utils.exception.PogamutIOExceptionprotected void shutdown(boolean waitForEndThread)
start()ed again.
waitForEndThread - whether we're being called from the waitForEnd thread.public void stop()
public Process getBotProcess()
public cz.cuni.amis.utils.flag.ImmutableFlag<Boolean> getRunning()
start()),
False == process was not started or has been already terminated, either by itself or via stop().
public boolean isRunning()
start()),
False == process was not started or has been already terminated, either by itself or via stop().
public Integer getExitValue()
public boolean isTimeout()
ProcessExecutionConfig.getTimeout() is specified, this will indicate whether the started process has
timed out or not.
public boolean isFailed(boolean report)
True == process has failed.
False == process is running or process has finished OK.
report - whether the reason of failure / success should be reported
public boolean isFailed()
True == process has failed.
False == process is running or process has finished OK.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||