Package eu.simuline.octave.exec
Class OctaveExec
- java.lang.Object
-
- eu.simuline.octave.exec.OctaveExec
-
public final class OctaveExec extends Object
The object connecting to the octave process.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
destroyed
private ReaderWriterPipeThread
errorStreamThread
The error thread of the error stream ofprocess
writing the error stream to a given writer.private ExecutorService
executor
Used in methodevalRW(WriteFunctor, ReadFunctor)
to submit essentially the write functor which submits the input and thereafter the read function which collects the output.private static org.apache.commons.logging.Log
LOG
static String
MSG_EXE_NH
static String
MSG_IOE_NH
static String
MSG_RTE_NH
private Process
process
The octave process created in the constructor with given command, arguments, environment and working directory.private BufferedReader
processReader
The input reader forprocess
derived fromProcess.getInputStream()
.private Writer
processWriter
The output writer forprocess
derived fromProcess.getOutputStream()
.private Random
random
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the octave process in an orderly fashion: Send commandexit
and expect a single line in return, namely an empty one.void
destroy()
Kill the octave process without remorse.void
evalRW(WriteFunctor input, ReadFunctor output)
Passesinput
to octave, get backoutput
and throws according exceptions if reading or writing went wrong.private String
generateSpacer()
private RuntimeException
getFromFuture(Future<Void> future)
Completes computation on future and returns an exception thrown or null.private boolean
isDestroyed()
Returnsdestroyed
.private OctaveException
reInstException(OctaveException exc)
Used bygetFromFuture(Future)
to re-instantiate anOctaveException
if this occurs as the cause of anExecutionException
.private void
setDestroyed(boolean destroyed)
Setsdestroyed
to the parameter value given.void
setErrorWriter(Writer writer)
-
-
-
Field Detail
-
MSG_IOE_NH
public static final String MSG_IOE_NH
- See Also:
- Constant Field Values
-
MSG_EXE_NH
public static final String MSG_EXE_NH
- See Also:
- Constant Field Values
-
MSG_RTE_NH
public static final String MSG_RTE_NH
- See Also:
- Constant Field Values
-
LOG
private static final org.apache.commons.logging.Log LOG
-
process
private final Process process
The octave process created in the constructor with given command, arguments, environment and working directory. This is initialized inOctaveExec(int, Writer, Writer, Charset, String[], String[], File)
and used inclose()
anddestroy()
only.
-
processWriter
private final Writer processWriter
The output writer forprocess
derived fromProcess.getOutputStream()
.
-
processReader
private final BufferedReader processReader
The input reader forprocess
derived fromProcess.getInputStream()
. This is used byevalRW(WriteFunctor, ReadFunctor)
and used to close viaclose()
.
-
executor
private final ExecutorService executor
Used in methodevalRW(WriteFunctor, ReadFunctor)
to submit essentially the write functor which submits the input and thereafter the read function which collects the output. Besides this, the executor is invoked to shutdown.
-
errorStreamThread
private final ReaderWriterPipeThread errorStreamThread
The error thread of the error stream ofprocess
writing the error stream to a given writer. This is used to close but also to change the error writer bysetErrorWriter(Writer)
.
-
destroyed
private boolean destroyed
-
random
private final Random random
-
-
Constructor Detail
-
OctaveExec
public OctaveExec(int numThreadsReuse, Writer stdinLog, Writer stderrLog, Charset charset, String[] cmdArray, String[] environment, File workingDir)
Will start the octave process.- Parameters:
numThreadsReuse
- the number of threads to be reused in a fixed thread pool. This is either positive or-1
, which means that a cached thread pool is used instead of a fixed one.stdinLog
- This writer will capture all that is written to the octave process via stdin, if null the data will not be captured.stderrLog
- This writer will capture all that is written from the octave process on stderr, if null the data will not be captured.charset
- the charset used for communication with the octave process.cmdArray
- The array consisting of command and arguments: The 0th entry is either the path to the octave program, or the command found by looking at the built-in variable "paths" reconstructing the path. starting with the 1th entry, may follow the array of arguments to start the octave program with. CAUTION: allowed values depend on the octave version.environment
- Either the environment for the octave process, i.e. the set of values of environment variables with each entry of the formname=value
or null to makeprocess
, the process created, inherit the environment of the current process.workingDir
- Either the working directory for the octave process, ornull
to makeprocess
, the process created, inherit the working directory of the current process.- Throws:
OctaveIOException
- If execution
-
-
Method Detail
-
generateSpacer
private String generateSpacer()
-
evalRW
public void evalRW(WriteFunctor input, ReadFunctor output)
Passesinput
to octave, get backoutput
and throws according exceptions if reading or writing went wrong.- Parameters:
input
- a write functor which represents the script to be executed in octave.output
- the read functor which reads the result of octave execution. After evaluation of this method, theoutput
is asked for the result.
-
getFromFuture
private RuntimeException getFromFuture(Future<Void> future)
Completes computation on future and returns an exception thrown or null.
-
reInstException
private OctaveException reInstException(OctaveException exc)
Used bygetFromFuture(Future)
to re-instantiate anOctaveException
if this occurs as the cause of anExecutionException
.
-
setDestroyed
private void setDestroyed(boolean destroyed)
Setsdestroyed
to the parameter value given.
-
isDestroyed
private boolean isDestroyed()
Returnsdestroyed
.
-
destroy
public void destroy()
Kill the octave process without remorse.
-
close
public void close()
Close the octave process in an orderly fashion: Send commandexit
and expect a single line in return, namely an empty one.- Throws:
OctaveIOException
- if
-
setErrorWriter
public void setErrorWriter(Writer writer)
- Parameters:
writer
- the new writer to write the error output to
-
-