org.mmbase.util.externalprocess
Class ProcessClosure

java.lang.Object
  |
  +--org.mmbase.util.externalprocess.ProcessClosure

public class ProcessClosure
extends java.lang.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:
Author:
Nico Klasens (Finalist IT Group)

Field Summary
protected  java.io.OutputStream error
          The stream where data is written to when piped from stderr
protected  org.mmbase.util.externalprocess.StreamCopyThread errorReader
          Thread for copying bytes from stderr to error
protected  java.io.InputStream input
          The stream where data is read from to pipe it to stdin
protected  org.mmbase.util.externalprocess.StreamCopyThread inputWriter
          Thread for copying bytes from input to stdin
protected  java.lang.String name
          the name of the process closure
protected  java.io.OutputStream output
          The stream where data is written to when piped from stdout
protected  org.mmbase.util.externalprocess.StreamCopyThread outputReader
          Thread for copying bytes from stdout to output
protected  java.lang.Process process
          the process object representing the external process
 
Constructor Summary
ProcessClosure(java.lang.String name, java.lang.Process process, java.io.InputStream inputStream, java.io.OutputStream outputStream, java.io.OutputStream errorStream)
          Creates a process reader .
 
Method Summary
 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 java.lang.String name
the name of the process closure

process

protected java.lang.Process process
the process object representing the external process

input

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

output

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

error

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

inputWriter

protected org.mmbase.util.externalprocess.StreamCopyThread inputWriter
Thread for copying bytes from input to stdin

outputReader

protected org.mmbase.util.externalprocess.StreamCopyThread outputReader
Thread for copying bytes from stdout to output

errorReader

protected org.mmbase.util.externalprocess.StreamCopyThread errorReader
Thread for copying bytes from stderr to error
Constructor Detail

ProcessClosure

public ProcessClosure(java.lang.String name,
                      java.lang.Process process,
                      java.io.InputStream inputStream,
                      java.io.OutputStream outputStream,
                      java.io.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

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 build 1.6.5.20030923