Class AbstractProcessOutput
- java.lang.Object
-
- com.github.fracpete.processoutput4j.output.AbstractProcessOutput
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
CollectingProcessOutput,ConsoleOutputProcessOutput,StreamingProcessOutput
public abstract class AbstractProcessOutput extends java.lang.Object implements java.io.SerializableAncestor for classes that give access to the output generated by a process.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String[]m_Commandthe command.protected java.lang.String[]m_Environmentthe environment variables.protected intm_ExitCodethe exit code.protected java.lang.Processm_Processthe process.protected AbstractProcessReaderm_ReaderStdErrfor monitoring stderr.protected AbstractProcessReaderm_ReaderStdOutfor monitoring stdout.protected AbstractProcessRunnablem_RunnableTimeoutfor monitoring timeouts.protected booleanm_TimedOutwhether the process has timed out.protected intm_TimeOutthe timeout for the process in seconds (ignored if < 1).
-
Constructor Summary
Constructors Constructor Description AbstractProcessOutput()Starts the monitoring process.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract AbstractProcessReaderconfigureStdErr()Configures the reader for stderr.protected abstract AbstractProcessReaderconfigureStdOut()Configures the reader for stdout.protected AbstractProcessRunnableconfigureTimeOutMonitor()Configures the runnable for watching for time outs.voiddestroy()Destroys the process if possible.voidflush()Flushes the readers.java.lang.String[]getCommand()Returns the command that was used for the process.java.lang.String[]getEnvironment()Returns the environment.intgetExitCode()Returns the exit code.java.lang.ProcessgetProcess()Returns the process.intgetTimeOut()Returns the timeout for the process in seconds.booleanhasSucceeded()Returns whether the process has succeeded.booleanhasTimedOut()Returns whether the process timed out and got terminated.protected voidinitialize()For initializing the members.voidmonitor(java.lang.ProcessBuilder builder)Performs the actual process monitoring.voidmonitor(java.lang.String[] cmd, java.lang.String[] env, java.lang.String input, java.lang.Process process)Performs the actual process monitoring.voidmonitor(java.lang.String input, java.lang.ProcessBuilder builder)Performs the actual process monitoring.voidmonitor(java.lang.String cmd, java.lang.String[] env, java.lang.Process process)Performs the actual process monitoring.voidmonitor(java.lang.String cmd, java.lang.String[] env, java.lang.String input, java.lang.Process process)Performs the actual process monitoring.voidsetTimeOut(int value)Sets the timeout for the process in seconds.java.lang.StringtoString()Returns a short description string.
-
-
-
Field Detail
-
m_Command
protected java.lang.String[] m_Command
the command.
-
m_Environment
protected java.lang.String[] m_Environment
the environment variables.
-
m_ExitCode
protected int m_ExitCode
the exit code.
-
m_Process
protected transient java.lang.Process m_Process
the process.
-
m_TimeOut
protected int m_TimeOut
the timeout for the process in seconds (ignored if < 1).
-
m_TimedOut
protected boolean m_TimedOut
whether the process has timed out.
-
m_ReaderStdErr
protected transient AbstractProcessReader m_ReaderStdErr
for monitoring stderr.
-
m_ReaderStdOut
protected transient AbstractProcessReader m_ReaderStdOut
for monitoring stdout.
-
m_RunnableTimeout
protected transient AbstractProcessRunnable m_RunnableTimeout
for monitoring timeouts.
-
-
Method Detail
-
initialize
protected void initialize()
For initializing the members.
-
setTimeOut
public void setTimeOut(int value)
Sets the timeout for the process in seconds.- Parameters:
value- the timeout (less than 1 for no timeout)
-
getTimeOut
public int getTimeOut()
Returns the timeout for the process in seconds.- Returns:
- the timeout (less than 1 for no timeout)
-
monitor
public void monitor(java.lang.ProcessBuilder builder) throws java.lang.ExceptionPerforms the actual process monitoring.- Parameters:
builder- the process builder to monitor- Throws:
java.lang.Exception- if writing to stdin fails
-
monitor
public void monitor(java.lang.String input, java.lang.ProcessBuilder builder) throws java.lang.ExceptionPerforms the actual process monitoring.- Parameters:
builder- the process builder to monitor- Throws:
java.lang.Exception- if writing to stdin fails
-
monitor
public void monitor(java.lang.String cmd, java.lang.String[] env, java.lang.Process process) throws java.lang.ExceptionPerforms the actual process monitoring.- Parameters:
cmd- the command that was usedenv- the environmentprocess- the process to monitor- Throws:
java.lang.Exception- if writing to stdin fails
-
monitor
public void monitor(java.lang.String cmd, java.lang.String[] env, java.lang.String input, java.lang.Process process) throws java.lang.ExceptionPerforms the actual process monitoring.- Parameters:
cmd- the command that was usedenv- the environmentinput- the input to be written to the process via stdin, ignored if nullprocess- the process to monitor- Throws:
java.lang.Exception- if writing to stdin fails
-
monitor
public void monitor(java.lang.String[] cmd, java.lang.String[] env, java.lang.String input, java.lang.Process process) throws java.lang.ExceptionPerforms the actual process monitoring.- Parameters:
cmd- the command that was usedenv- the environmentinput- the input to be written to the process via stdin, ignored if nullprocess- the process to monitor- Throws:
java.lang.Exception- if writing to stdin fails
-
configureStdErr
protected abstract AbstractProcessReader configureStdErr()
Configures the reader for stderr.- Returns:
- the configured reader
-
configureStdOut
protected abstract AbstractProcessReader configureStdOut()
Configures the reader for stdout.- Returns:
- the configured reader
-
configureTimeOutMonitor
protected AbstractProcessRunnable configureTimeOutMonitor()
Configures the runnable for watching for time outs.- Returns:
- the configured runnable
-
getCommand
public java.lang.String[] getCommand()
Returns the command that was used for the process.- Returns:
- the command
-
getEnvironment
public java.lang.String[] getEnvironment()
Returns the environment.- Returns:
- the environment, null if process inherited current one
-
hasSucceeded
public boolean hasSucceeded()
Returns whether the process has succeeded.- Returns:
- true if succeeded, i.e., exit code = 0 and not timedout
- See Also:
hasTimedOut()
-
getExitCode
public int getExitCode()
Returns the exit code.- Returns:
- the exit code
-
hasTimedOut
public boolean hasTimedOut()
Returns whether the process timed out and got terminated.- Returns:
- true if timedout
- See Also:
getTimeOut(),setTimeOut(int)
-
getProcess
public java.lang.Process getProcess()
Returns the process.- Returns:
- the process, null if not available
-
flush
public void flush()
Flushes the readers.
-
destroy
public void destroy()
Destroys the process if possible.
-
toString
public java.lang.String toString()
Returns a short description string.- Overrides:
toStringin classjava.lang.Object- Returns:
- the description
-
-