public class ProcessExecution extends Object
ProcessExecutionConfig.
The class is not suitable for inheritance ... better copy-paste and adjust for yourself.
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
ProcessExecution(ProcessExecutionConfig config,
Logger log) |
| Modifier and Type | Method and Description |
|---|---|
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). |
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 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
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)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 reportedpublic boolean isFailed()
True == process has failed.
False == process is running or process has finished OK.
Copyright © 2018 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All rights reserved.