ManagedProcess

public class ManagedProcess implements ManagedProcessState

Managed OS Process (Executable, Program, Command). Created by build.

Intended for controlling external "tools", often "daemons", which produce some text-based control output. In this form not yet suitable for programs returning binary data via stdout (but could be extended).

Does reasonably extensive logging about what it's doing (contrary to Apache Commons Exec), including logging the processes stdout &stderr, into SLF4J (not the System.out.Console).

Author

Michael Vorburger

Neelesh Shastry

William Dutton

See also

Executor

Internally based on http://commons.apache.org/exec/ but intentionally not exposing this; could be switched later, if there is any need.

Properties

Link copied to clipboard
public final static int EXIT_VALUE_DESTROYED
Synthetic exit code returned when this process was explicitly destroyed via destroy rather than terminating normally.
Link copied to clipboard
public final static int EXIT_VALUE_STILL_RUNNING
Synthetic exit code used to indicate that the process was still running when a bounded wait timed out (see waitForExitMaxMs).

Functions

Link copied to clipboard
public void destroy()
Kills the Process.
Link copied to clipboard
public int exitValue()
Returns the exit value for the subprocess.
Link copied to clipboard
public String getConsole()
Returns the recent console output captured from the process (stdout and stderr).
Link copied to clipboard
Returns the path of the executable that will be launched.
Link copied to clipboard
Returns a formatted string with the last N lines of console output for diagnostics.
Link copied to clipboard
Returns a descriptive name of the process suitable for logs (typically includes the command and, if available, the working directory).
Link copied to clipboard
public boolean isAlive()
Tests if this process is alive.
Link copied to clipboard
public void notifyProcessHalted()
Allows LoggingExecuteResultHandler to notify if process has halted (success or failure).
Link copied to clipboard
public synchronized ManagedProcess start()
Starts the Process.
Link copied to clipboard
public boolean startAndWaitForConsoleMessageMaxMs(String messageInConsole, long maxWaitUntilReturning)
Starts the Process and waits (blocks) until the process prints a certain message.
Link copied to clipboard
public int waitForExit()
Waits for the process to terminate.
Link copied to clipboard
public int waitForExitMaxMs(long maxWaitUntilReturning)
Like waitForExit, but waits max.
Link copied to clipboard
public ManagedProcess waitForExitMaxMsOrDestroy(long maxWaitUntilDestroyTimeout)
Like waitForExit, but waits max.
Link copied to clipboard
public boolean watchDogKilledProcess()
Indicates whether the watchdog forcibly killed the process.