|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.javasoft.job.ExecJobMonitor
public class ExecJobMonitor
The ExecJobMonitor adds some functions specific for
ExecJobs to the normal JobMonitor functions. For instance,
input and output stream handling methods are available, such as piping the
output of the job to some output stream, or piping the output of one job to
the input of another job.
| Constructor Summary | |
|---|---|
protected |
ExecJobMonitor(Process process)
|
| Method Summary | ||
|---|---|---|
protected void |
closeStreams()
Close the registered streams on termination |
|
protected static ExecJobMonitor |
createForException(Throwable th)
|
|
InputStream |
getErrorStream()
|
|
InputStream |
getInputStream()
|
|
JobResult<Void> |
getJobResult()
|
|
OutputStream |
getOutputStream()
|
|
protected Process |
getProcess()
|
|
void |
interrupt()
Interrupts the process or thread, or does nothing if JobMonitor.isRunning() returns false. |
|
boolean |
isRunning()
|
|
void |
pipeErr(OutputStream err,
boolean closeOnTerminate)
Pipe the error stream of the current process to the given stream |
|
void |
pipeFrom(ExecJobMonitor src,
boolean closeOnTerminate)
Pipe the output and error stream of src to the standard
input of the current process. |
|
void |
pipeFrom(InputStream in,
boolean closeOnTerminate)
Read from the given input stream and pipe it to the standard input of the current process. |
|
void |
pipeIn(InputStream in,
boolean closeOnTerminate)
Read from the given input stream and pipe it to the standard input of the current process. |
|
void |
pipeOut(OutputStream out,
boolean closeOnTerminate)
Pipe the output stream of the current process to the given stream |
|
void |
pipeTo(ExecJobMonitor dst,
boolean closeOnTerminate)
Pipe the output and error stream of the current process to the standard input of dst. |
|
void |
pipeTo(OutputStream out,
OutputStream err,
boolean closeOnTerminate)
Pipe the output and error stream of the current process to the given streams. |
|
void |
pushInput(String... inputLines)
Pushes the given lines to the process' output stream, i.e. |
|
protected void |
setResult(JobResult<Void> result)
|
|
JobResult<Void> |
waitForResult()
Blocks the current thread until the result is available. |
|
|
waitForResultThrowException(Class<E> exClass)
Like waitForResult(), but if the result was exceptional, an
Exception is thrown. |
|
String |
waitForStdOutString()
Like waitForResult(), but returning a string containing the
stuff which was written to the standard output of the process. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected ExecJobMonitor(Process process)
| Method Detail |
|---|
protected static ExecJobMonitor createForException(Throwable th)
protected Process getProcess()
protected void setResult(JobResult<Void> result)
public void interrupt()
JobMonitorJobMonitor.isRunning() returns false. The
JobMonitor.waitForResult() method receives an InterruptedException
if the job status is affected by this call.
interrupt in interface JobMonitor<Void>public boolean isRunning()
isRunning in interface JobMonitor<Void>public JobResult<Void> getJobResult()
getJobResult in interface JobMonitor<Void>null if JobMonitor.isRunning() returns
true
public JobResult<Void> waitForResult()
throws InterruptedException
JobMonitor
waitForResult in interface JobMonitor<Void>InterruptedException - if execution has been interrupted, e.g.
by calling JobMonitor.interrupt()
public <E extends Throwable> void waitForResultThrowException(Class<E> exClass)
throws E extends Throwable
waitForResult(), but if the result was exceptional, an
Exception is thrown. The exception type to be thrown is defined with the
exClass parameter, every exception not being of that type
will be transformed into a RuntimeException if necessary.
exClass - The desired exception type, e.g. use
RuntimeException.class that only runtime
exceptions are thrown, or Throwable.class
to rethrow every occuring exception unchanged.
E - The exception of the specified type
RuntimeException - If an exception was thrown not being of type E
and not being an Error. If it was already a
runtime exception, it is rethrown, if not, it
is nested in a runtime exception which is then
thrown.
Error - If an error was thrown not being of type E
E extends Throwable
public String waitForStdOutString()
throws ExecException,
ExitValueException,
StdErrNonEmptyException,
InterruptedException
waitForResult(), but returning a string containing the
stuff which was written to the standard output of the process. If the
process also wrote to the standard error, a
StdErrNonEmptyException is thrown. If the process exits with an
exit code unequal to 0, an ExitValueException is thrown.
ExitValueException - if the process terminated with an exit
value unequal to 0
StdErrNonEmptyException - if the process wrote to the standard
error
InterruptedException - if waiting for termination of the
process was interrupted, e.g.
by calling interrupt()
ExecException - if any other exception occurred during
the process executionpublic InputStream getErrorStream()
public InputStream getInputStream()
public OutputStream getOutputStream()
public void pushInput(String... inputLines)
Pushes the given lines to the process' output stream, i.e. to the standard input. Each line is printed separately, followed by a system dependant new line separator. After pushing all lines, the standard input is closed to indicate end of input.
Pushing the lines is performed in a separate thread.
inputLines - The lines to push to the standard input
public void pipeFrom(ExecJobMonitor src,
boolean closeOnTerminate)
src to the standard
input of the current process.
This is a convenience method, a call behaves exactly like calling
pipeIn(InputStream, boolean) with ouptut and error stream of
src.
Piping is performed in separate threads.
src - the source process to get the input fromcloseOnTerminate - if true, standard output and error
of src will be closed when the
current process terminates
public void pipeTo(ExecJobMonitor dst,
boolean closeOnTerminate)
dst.This is a convenience method, a call behaves exactly like calling
pipeOut(OutputStream, boolean) and
pipeErr(OutputStream, boolean) with the standard input of
dst.
Piping is performed in separate threads.
dst - the target process to write the output tocloseOnTerminate - if true, standard input of
dst will be closed when the
current process terminates
public void pipeTo(OutputStream out,
OutputStream err,
boolean closeOnTerminate)
This is a convenience method, a call behaves exactly like calling
pipeOut(OutputStream, boolean) and
pipeErr(OutputStream, boolean) with the respective streams.
Piping is performed in separate threads.
out - the target stream for standard outputerr - the target stream for standard errorcloseOnTerminate - if true, both target streams will
be closed when the current process terminates
public void pipeFrom(InputStream in,
boolean closeOnTerminate)
This is a convenience method, a call behaves exactly like calling
pipeIn(InputStream, boolean).
Piping is performed in a separate thread.
in - the source stream to get the input fromcloseOnTerminate - if true, the input stream
in will be closed when the
current process terminates
public void pipeOut(OutputStream out,
boolean closeOnTerminate)
Piping is performed in a separate thread.
out - the target stream for standard outputcloseOnTerminate - if true, the output stream
out will be closed when the current
process terminates
public void pipeErr(OutputStream err,
boolean closeOnTerminate)
Piping is performed in a separate thread.
err - the target stream for standard errorcloseOnTerminate - if true, the output stream
err will be closed when the current
process terminates
public void pipeIn(InputStream in,
boolean closeOnTerminate)
Piping is performed in a separate thread.
in - the source stream to get the input fromcloseOnTerminate - if true, the input stream
in will be closed when the
current process terminatesprotected void closeStreams()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||