public final class ProcessMonitor extends Object implements ServiceThread.Target
Monitors and controls the execution of a subprocess.
Modifier and Type | Class and Description |
---|---|
static class |
ProcessMonitor.Builder
Builder.
|
Modifier and Type | Method and Description |
---|---|
boolean |
activateProcess()
Activates the process object.
|
void |
close()
Closes this.
|
void |
freeProcess()
Frees the process.
|
void |
limit(long timeLimit)
Limits processing time.
|
static ProcessMonitor.Builder |
newBuilder()
Returns a new builder.
|
static long |
newRequestID()
Returns a new request ID.
|
String |
readLine()
Reads a line from the process standard output.
|
void |
run()
Runs within the
Thread to monitor the execution of the
process. |
boolean |
writeLine(String line)
Writes a line to the process standard input.
|
@Nonnull @CheckReturnValue public static ProcessMonitor.Builder newBuilder()
@CheckReturnValue public static long newRequestID()
This utility method generates a new value each time it is called. The value will be unique for the class and will always be increasing.
It is safe for use by concurrent threads.
@CheckReturnValue public boolean activateProcess()
Unless it is already running, the process will be created and a new thread will be started to monitor its execution. Any sheduled interrupt will be cancelled.
public void close()
public void freeProcess()
If there is a grace time and a timer object is available, an interrupt will be scheduled; otherwise, unless the process is to be kept indefinitely, it is interrupted.
public void limit(long timeLimit)
timeLimit
- The time limit in millis.@Nullable @CheckReturnValue public String readLine()
Ignores empty lines or lines containing only spaces.
public void run()
Thread
to monitor the execution of the
process.
Waits until the Thread is interrupted or the process dies by itself. It will then perform a cleanup of the process context; this will close stdin for the monitored process which, if still alive, is expected to stop.
run
in interface ServiceThread.Target
@CheckReturnValue public boolean writeLine(@Nonnull String line)
line
- The line.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.