edu.rice.cs.util
Class ProcessSequence

java.lang.Object
  extended by java.lang.Process
      extended by edu.rice.cs.util.ProcessSequence

public class ProcessSequence
extends Process

This class represents a sequence of processes. The inputs and outputs of the processes are not connected. One process wait until the preceding process has terminated. The class allows the entire sequence to be treated as if it were just one process. The constructor starts the first subprocess.


Nested Class Summary
protected  class ProcessSequence.ProcessSequenceThreadGroup
          Thread group for all threads that deal with this process sequence.
 
Field Summary
protected  boolean _aborted
          True if the execution was aborted.
protected  PipedInputStream _combinedErrorStream
          The combined error stream of all processes.
protected  JoinInputStream _combinedInputJoinedWithDebugStream
          The combined input stream of all the processes, plus a debug stream.
protected  PipedInputStream _combinedInputStream
          The combined input stream of all processes.
protected  OutputStream _combinedOutputStream
          The output stream of the currently executing process.
protected  PipedOutputStream _combinedStdErrStream
          The stream into which all outputs to stderr are written.
protected  PipedOutputStream _combinedStdOutStream
          The stream into which all outputs to stdout are written.
protected  ProcessCreator[] _creators
          The process creators that create the processes in this process sequence.
protected  Thread _deathThread
          Thread that monitors the subprocesses and starts the next process when the previous one has terminated.
protected  PipedInputStream _debugInputStream
          Debug input and output stream.
protected  PrintWriter _debugOutput
          Debug output that gets joined with the streams from the processes.
protected  PipedOutputStream _debugOutputStream
           
protected  int _index
          Index of the currently running process.
protected  Process[] _processes
          The processes inside this process sequence.
protected  StreamRedirectThread _stdErrRedirector
          The redirector thread that moves stderr output from one process to the input of the next process.
protected  StreamRedirectThread _stdOutRedirector
          The redirector thread that moves stdout output from one process to the input of the next process.
protected static Process DUMMY_PROCESS
          A process that does nothing.
 
Constructor Summary
ProcessSequence(ProcessCreator[] pcs)
          Constructor for a process sequence consisting of the individual processes provided.
 
Method Summary
protected  void connectProcess(Process p)
          Connect the streams of the specified process.
 void destroy()
          Kills all subprocesses.
 int exitValue()
          Returns the exit value for the subprocess.
 InputStream getErrorStream()
          Gets the error stream of the process sequence, i.e.
 InputStream getInputStream()
          Gets the input stream of the process sequence, i.e.
 OutputStream getOutputStream()
          Gets the output stream of the process sequence, i.e.
protected  void stopAllRedirectors()
          Set the stop flags for all redirector threads.
 int waitFor()
          Causes the current thread to wait, if necessary, until the process sequence has terminated, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_creators

protected ProcessCreator[] _creators
The process creators that create the processes in this process sequence.


_processes

protected Process[] _processes
The processes inside this process sequence.


_index

protected volatile int _index
Index of the currently running process.


_aborted

protected volatile boolean _aborted
True if the execution was aborted.


_stdOutRedirector

protected StreamRedirectThread _stdOutRedirector
The redirector thread that moves stdout output from one process to the input of the next process.


_stdErrRedirector

protected StreamRedirectThread _stdErrRedirector
The redirector thread that moves stderr output from one process to the input of the next process.


_combinedInputStream

protected PipedInputStream _combinedInputStream
The combined input stream of all processes.


_combinedStdOutStream

protected PipedOutputStream _combinedStdOutStream
The stream into which all outputs to stdout are written.


_combinedInputJoinedWithDebugStream

protected JoinInputStream _combinedInputJoinedWithDebugStream
The combined input stream of all the processes, plus a debug stream.


_debugOutput

protected PrintWriter _debugOutput
Debug output that gets joined with the streams from the processes.


_debugInputStream

protected PipedInputStream _debugInputStream
Debug input and output stream.


_debugOutputStream

protected PipedOutputStream _debugOutputStream

_combinedErrorStream

protected PipedInputStream _combinedErrorStream
The combined error stream of all processes.


_combinedStdErrStream

protected PipedOutputStream _combinedStdErrStream
The stream into which all outputs to stderr are written.


_combinedOutputStream

protected volatile OutputStream _combinedOutputStream
The output stream of the currently executing process.


_deathThread

protected Thread _deathThread
Thread that monitors the subprocesses and starts the next process when the previous one has terminated.


DUMMY_PROCESS

protected static final Process DUMMY_PROCESS
A process that does nothing.

Constructor Detail

ProcessSequence

public ProcessSequence(ProcessCreator[] pcs)
Constructor for a process sequence consisting of the individual processes provided.

Parameters:
pcs - array of ProcessCreators
Method Detail

getOutputStream

public OutputStream getOutputStream()
Gets the output stream of the process sequence, i.e. the combined output stream of all the processes in the sequence.

Specified by:
getOutputStream in class Process
Returns:
the output stream of the process sequence.

getErrorStream

public InputStream getErrorStream()
Gets the error stream of the process sequence, i.e. the combined error stream of all the processes in the sequence.

Specified by:
getErrorStream in class Process
Returns:
the error stream of the process sequence.

getInputStream

public InputStream getInputStream()
Gets the input stream of the process sequence, i.e. the combined input stream of all the processes in the sequence.

Specified by:
getInputStream in class Process
Returns:
the input stream of the process chain

waitFor

public int waitFor()
            throws InterruptedException
Causes the current thread to wait, if necessary, until the process sequence has terminated, i.e. until all processes in the sequence have terminated. This method returns immediately if all subprocesses have already terminated. If any of the subprocess has not yet terminated, the calling thread will be blocked until all subprocesses exit.

Specified by:
waitFor in class Process
Returns:
the exit value of the process chain, i.e. the exit code of the last process in the sequence.
Throws:
InterruptedException - if the current thread is interrupted by another thread while it is waiting, then the wait is ended and an InterruptedException is thrown.

exitValue

public int exitValue()
Returns the exit value for the subprocess.

Specified by:
exitValue in class Process
Returns:
the exit value of the subprocess represented by this Process object. by convention, the value 0 indicates normal termination.
Throws:
IllegalThreadStateException - if the subprocess represented by this Process object has not yet terminated.

destroy

public void destroy()
Kills all subprocesses. The subprocesses represented by this ProcessChain object is forcibly terminated.

Specified by:
destroy in class Process

stopAllRedirectors

protected void stopAllRedirectors()
Set the stop flags for all redirector threads.


connectProcess

protected void connectProcess(Process p)
Connect the streams of the specified process.