org.mmbase.util.externalprocess
Class ProcessClosure

java.lang.Object
  extended by org.mmbase.util.externalprocess.ProcessClosure

public class ProcessClosure
extends Object

ProcessClosure handles the reading of the stdout and stderr of a external process. A reader can block the calling thread until it is finished reading (readBlocking). Or the reader can immidiately return when reading of the stdout and stderr begins (readNonBlocking). ProcessClosure handles the writing of the stdin of a external process. A writer can block the calling thread until it is finished writing to the stdin and reading the stdout and stderr (writeBlocking). Or the writer can imidiately return when writing to stdin and reading of the stdout and sterr begins (writeNonBlocking)

Since:
MMBase-1.6
Version:
$Id: ProcessClosure.java 36921 2009-07-14 12:27:40Z michiel $
Author:
Nico Klasens (Finalist IT Group)

Field Summary
protected  long count
           
protected  OutputStream error
          The stream where data is written to when piped from stderr
protected  StreamCopyThread errorReader
          Thread for copying bytes from stderr to error
protected  InputStream input
          The stream where data is read from to pipe it to stdin
protected  StreamCopyThread inputWriter
          Thread for copying bytes from input to stdin
protected  String name
          the name of the process closure
protected  OutputStream output
          The stream where data is written to when piped from stdout
protected  StreamCopyThread outputReader
          Thread for copying bytes from stdout to output
protected  Process process
          the process object representing the external process
 
Constructor Summary
ProcessClosure(String name, Process process, InputStream inputStream, OutputStream outputStream, OutputStream errorStream)
          Creates a process reader .
 
Method Summary
 long getCount()
           
 boolean isAlive()
          Process closure is alive when the external process and writer/reader threads are still busy
 void readBlocking()
          read data from the external process and block the calling thread until reading is finished
 void readNonBlocking()
          read data from the external process without blocking the calling thread
 void terminate()
          Forces the termination of the launched process
protected  void waitForProcess()
          wait for the external process.to end
protected  void waitForReaders()
          wait for the reading threads to finish copying
protected  void waitForWriter()
          wait for the writing thread to finish copying
 void writeBlocking()
          write data to the external process and block the calling thread until writing and reading is finished
 void writeNonBlocking()
          write data to the external process without blocking the calling thread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected String name
the name of the process closure


process

protected Process process
the process object representing the external process


input

protected InputStream input
The stream where data is read from to pipe it to stdin


output

protected OutputStream output
The stream where data is written to when piped from stdout


error

protected OutputStream error
The stream where data is written to when piped from stderr


inputWriter

protected StreamCopyThread inputWriter
Thread for copying bytes from input to stdin


outputReader

protected StreamCopyThread outputReader
Thread for copying bytes from stdout to output


errorReader

protected StreamCopyThread errorReader
Thread for copying bytes from stderr to error


count

protected long count
Constructor Detail

ProcessClosure

public ProcessClosure(String name,
                      Process process,
                      InputStream inputStream,
                      OutputStream outputStream,
                      OutputStream errorStream)
Creates a process reader .

Parameters:
name - the name of the reader
inputStream - process stdin is read from this stream. Can be null, if not interested in writing the input
outputStream - process stdout is written to this stream. Can be null, if not interested in reading the output
errorStream - porcess stderr is written to this stream. Can be null, if not interested in reading the output
Method Detail

readNonBlocking

public void readNonBlocking()
read data from the external process without blocking the calling thread


writeNonBlocking

public void writeNonBlocking()
write data to the external process without blocking the calling thread


getCount

public long getCount()

readBlocking

public void readBlocking()
read data from the external process and block the calling thread until reading is finished


writeBlocking

public void writeBlocking()
write data to the external process and block the calling thread until writing and reading is finished


waitForProcess

protected void waitForProcess()
wait for the external process.to end


waitForReaders

protected void waitForReaders()
wait for the reading threads to finish copying


waitForWriter

protected void waitForWriter()
wait for the writing thread to finish copying


isAlive

public boolean isAlive()
Process closure is alive when the external process and writer/reader threads are still busy

Returns:
true if is alive and false otherwise

terminate

public void terminate()
Forces the termination of the launched process



MMBase 2.0-SNAPSHOT - null