Package org.zeroturnaround.exec
Class WaitForProcess
- java.lang.Object
-
- org.zeroturnaround.exec.WaitForProcess
-
- All Implemented Interfaces:
java.util.concurrent.Callable<ProcessResult>
class WaitForProcess extends java.lang.Object implements java.util.concurrent.Callable<ProcessResult>
Handles the executed process.
-
-
Field Summary
Fields Modifier and Type Field Description private ProcessAttributesattributesSet of main attributes used to start the process.private ProcessClosercloserHelper for closing the process' standard streams.private ProcessListenerlistenerProcess event listener (notnull).private static org.slf4j.Loggerlogprivate MessageLoggermessageLoggerHelper for logging messages about starting and waiting for the processes.private java.io.ByteArrayOutputStreamoutBuffer where the process output is redirected to ornullif it's not used.private java.lang.Processprocessprivate ProcessStopperstopperHelper for stopping the process in case of interruption.private java.lang.ThreadworkerThreadThread which executes this operation.
-
Constructor Summary
Constructors Constructor Description WaitForProcess(java.lang.Process process, ProcessAttributes attributes, ProcessStopper stopper, ProcessCloser closer, java.io.ByteArrayOutputStream out, ProcessListener listener, MessageLogger messageLogger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddExceptionMessageSuffix(java.lang.StringBuilder sb)Adds a suffix for an error message including: executed command working directory (unless it's inherited from parent) environment (unless it's the same with the parent) output read so far (unless it's not read)ProcessResultcall()private ProcessOutputgetCurrentOutput()java.lang.ProcessgetProcess()java.lang.StackTraceElement[]getStackTrace()java.lang.StringtoString()
-
-
-
Field Detail
-
log
private static final org.slf4j.Logger log
-
process
private final java.lang.Process process
-
attributes
private final ProcessAttributes attributes
Set of main attributes used to start the process.
-
stopper
private final ProcessStopper stopper
Helper for stopping the process in case of interruption.
-
closer
private final ProcessCloser closer
Helper for closing the process' standard streams.
-
out
private final java.io.ByteArrayOutputStream out
Buffer where the process output is redirected to ornullif it's not used.
-
listener
private final ProcessListener listener
Process event listener (notnull).
-
messageLogger
private final MessageLogger messageLogger
Helper for logging messages about starting and waiting for the processes.
-
workerThread
private volatile java.lang.Thread workerThread
Thread which executes this operation.
-
-
Constructor Detail
-
WaitForProcess
public WaitForProcess(java.lang.Process process, ProcessAttributes attributes, ProcessStopper stopper, ProcessCloser closer, java.io.ByteArrayOutputStream out, ProcessListener listener, MessageLogger messageLogger)
-
-
Method Detail
-
getProcess
public java.lang.Process getProcess()
- Returns:
- the sub process.
-
call
public ProcessResult call() throws java.io.IOException, java.lang.InterruptedException
- Specified by:
callin interfacejava.util.concurrent.Callable<ProcessResult>- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
getCurrentOutput
private ProcessOutput getCurrentOutput()
-
addExceptionMessageSuffix
public void addExceptionMessageSuffix(java.lang.StringBuilder sb)
Adds a suffix for an error message including:- executed command
- working directory (unless it's inherited from parent)
- environment (unless it's the same with the parent)
- output read so far (unless it's not read)
- Parameters:
sb- where the suffix is appended to.
-
getStackTrace
public java.lang.StackTraceElement[] getStackTrace()
- Returns:
- current stacktrace of the worker thread,
nullif this operation is currently not running.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-