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 ProcessAttributes
attributes
Set of main attributes used to start the process.private ProcessCloser
closer
Helper for closing the process' standard streams.private ProcessListener
listener
Process event listener (notnull
).private static org.slf4j.Logger
log
private MessageLogger
messageLogger
Helper for logging messages about starting and waiting for the processes.private java.io.ByteArrayOutputStream
out
Buffer where the process output is redirected to ornull
if it's not used.private java.lang.Process
process
private ProcessStopper
stopper
Helper for stopping the process in case of interruption.private java.lang.Thread
workerThread
Thread 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 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)ProcessResult
call()
private ProcessOutput
getCurrentOutput()
java.lang.Process
getProcess()
java.lang.StackTraceElement[]
getStackTrace()
java.lang.String
toString()
-
-
-
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 ornull
if 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:
call
in interfacejava.util.concurrent.Callable<ProcessResult>
- Throws:
java.io.IOException
java.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,
null
if this operation is currently not running.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-