Package eu.simuline.octave
Class OctaveEngineFactory
- java.lang.Object
-
- eu.simuline.octave.OctaveEngineFactory
-
public final class OctaveEngineFactory extends Object
Factory that creates OctaveEngines. First of all, create an OctaveEngineFactory using the default constructorOctaveEngineFactory()
then, optionally, change parameters and finally create an Octave Engine usinggetScriptEngine()
with the current parameters. To set a parameter, use the various setter methods. In the documentation of each setter method, also the default value is documented which is used to create anOctaveEngine
if the setter method is not invoked. Note that setter methods return the factory after modification and so setter methods may be queued also.
-
-
Field Summary
Fields Modifier and Type Field Description private String[]
argsArray
The array of arguments of the octave engines created.Charset
charset
The character set used to transform input stream , output stream and error stream for 'octave process'.private String[]
environment
An array of strings of the formname=value
representing the environment, i.e. the set of environment variables ornull
.private Writer
errWriter
The error writer for the octave process.private int
numThreadsReuse
The number of threads to be reused or-1
if there is no limit.private Writer
octaveInputLog
If this is notnull
, the octave engine created writes the output to that log writer also.private String
octaveProgramCmd
The command which determines the octave executable ifoctaveProgramFile
isnull
and if the propertyPROPERTY_EXECUTABLE
is not set.private File
octaveProgramFile
The file containing the octave program or isnull
.static String
PROPERTY_EXECUTABLE
The custom system property which determines where the executable is found ifoctaveProgramFile
is not set.private File
workingDir
The file representing the working directory ornull
.
-
Constructor Summary
Constructors Constructor Description OctaveEngineFactory()
Default constructor creating a factory with default parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OctaveEngine
getScriptEngine()
Returns a script engine with the parameters set for this factory.OctaveEngineFactory
setArgsArray(String[] argsArray)
Sets an array of argumentsargsArray
used when creating anOctaveEngine
.OctaveEngineFactory
setCharset(Charset charset)
Sets the encoding of input, output and error stream of the 'octave process'.OctaveEngineFactory
setEnvironment(String[] environment)
Setter method forenvironment
.OctaveEngineFactory
setErrorWriter(Writer errWriter)
Setter method forerrWriter
.OctaveEngineFactory
setNumThreadsReuse(int numThreadsReuse)
Sets the number of threads to be reused or-1
which indicates no limit.OctaveEngineFactory
setOctaveInputLog(Writer octaveInputLog)
Setter method foroctaveInputLog
.OctaveEngineFactory
setOctaveProgramCmd(String octaveProgramCmd)
Setter method foroctaveProgramCmd
.OctaveEngineFactory
setOctaveProgramFile(File octaveProgramFile)
Setter method foroctaveProgramFile
.OctaveEngineFactory
setWorkingDir(File workingDir)
Setter method forworkingDir
.
-
-
-
Field Detail
-
PROPERTY_EXECUTABLE
public static final String PROPERTY_EXECUTABLE
The custom system property which determines where the executable is found ifoctaveProgramFile
is not set. A custom property is set when invoking the runtime with the option-D
For examplejava -Deu.simuline.octave.executable=myoctave Application
runs classApplication
setting the system propertyeu.simuline.octave.executable
to- See Also:
- Constant Field Values
-
octaveInputLog
private Writer octaveInputLog
If this is notnull
, the octave engine created writes the output to that log writer also. By default, this isnull
. The according setter method issetOctaveInputLog(Writer)
.
-
charset
public Charset charset
The character set used to transform input stream , output stream and error stream for 'octave process'. The default value isStandardCharsets.UTF_8
which is the only value for octave TBD: reference.
-
errWriter
private Writer errWriter
The error writer for the octave process. By default, this is justSystem.err
. The according setter method issetErrorWriter(Writer)
.
-
octaveProgramFile
private File octaveProgramFile
The file containing the octave program or isnull
. In the latter case, the name of the octave program command is determined as described foroctaveProgramCmd
. By default, this isnull
. The according setter method issetOctaveProgramFile(File)
.
-
octaveProgramCmd
private String octaveProgramCmd
The command which determines the octave executable ifoctaveProgramFile
isnull
and if the propertyPROPERTY_EXECUTABLE
is not set. By default, this is "octave
". The according setter method issetOctaveProgramCmd(String)
.
-
argsArray
private String[] argsArray
The array of arguments of the octave engines created. For details, see octave user manual, version 5.2.0, Section 2.1.1.Default value of this field is default value for octave engines created. The default value consists of the following components:
-
--silent
: prevents octave from printing the usual greeting and version message at startup. -
--no-init-file
,--no-site-file
prevents octave from reading the initialization files~/.octaverc
,.octaverc
and site-wideoctaverc
.
--silent
: If not set this, octave's greeting message causes an exception. Option--no-init-file
makes the result independent of user input, whereas--no-init-file
and--no-site-file
makes it independent of initialization files. Since this is used to create scripting engines, line editing and history seem superfluous and so--no-line-editing
and--no-history
seem appropriate. Note that--no-init-file
and--no-site-file
may be appropriate or not. Instead of combining--no-init-file
and--no-site-file
equivalently one can specify--norc
. As this is the default,--no-gui?
is not needed. TBD: discuss --no-window-system Note that this array may be empty but can never benull
. -
-
environment
private String[] environment
An array of strings of the formname=value
representing the environment, i.e. the set of environment variables ornull
. In the latter case, the environment is inherited from the current process. This field is initialized withnull
.
-
workingDir
private File workingDir
The file representing the working directory ornull
. In the latter case, the working directory is inherited from the current process. By default, this isnull
.
-
numThreadsReuse
private int numThreadsReuse
The number of threads to be reused or-1
if there is no limit. By default, this is2
.
-
-
Method Detail
-
getScriptEngine
public OctaveEngine getScriptEngine()
Returns a script engine with the parameters set for this factory.- Returns:
- a new OctaveEngine with the current parameters.
-
setOctaveInputLog
public OctaveEngineFactory setOctaveInputLog(Writer octaveInputLog)
Setter method foroctaveInputLog
.- Parameters:
octaveInputLog
- the octave input log to set ornull
if no such log is wanted.- Returns:
- this octave engine factory after modification.
-
setErrorWriter
public OctaveEngineFactory setErrorWriter(Writer errWriter)
Setter method forerrWriter
.- Parameters:
errWriter
- the errWriter to set This may be null TBC- Returns:
- this octave engine factory after modification.
-
setOctaveProgramFile
public OctaveEngineFactory setOctaveProgramFile(File octaveProgramFile)
Setter method foroctaveProgramFile
.- Parameters:
octaveProgramFile
- the octaveProgramFile to set ornull
.- Returns:
- this octave engine factory after modification.
-
setOctaveProgramCmd
public OctaveEngineFactory setOctaveProgramCmd(String octaveProgramCmd)
Setter method foroctaveProgramCmd
. This takes effect only, ifoctaveProgramFile
isnull
and if the propertyPROPERTY_EXECUTABLE
is not set.- Parameters:
octaveProgramCmd
- the octave program executable to set- Returns:
- this octave engine factory after modification.
- Throws:
NullPointerException
- ifoctaveProgramCmd
isnull
.
-
setArgsArray
public OctaveEngineFactory setArgsArray(String[] argsArray)
Sets an array of argumentsargsArray
used when creating anOctaveEngine
. The validity of the argument string is not proved. Note that subsequent changes on the arrayargsArray
do not have any influence on this factory. The default options and a discussion of necessary options are documented withargsArray
.- Parameters:
argsArray
- the arguments as an array to set- Returns:
- this octave engine factory after modification.
- Throws:
NullPointerException
- ifargsArray
isnull
or contains anull
entry.
-
setCharset
public OctaveEngineFactory setCharset(Charset charset)
Sets the encoding of input, output and error stream of the 'octave process'. The appropriate value for octave seems to beStandardCharsets.UTF_8
so this method may be used rarely.- Parameters:
charset
- the new charset.- Returns:
- this octave engine factory after modification.
- Throws:
NullPointerException
- ifcharset
isnull
.
-
setEnvironment
public OctaveEngineFactory setEnvironment(String[] environment)
Setter method forenvironment
. Note that subsequent changes on the arrayenvironment
do not have any influence on this factory. The details are documented withenvironment
.- Parameters:
environment
- the environment- as an array of entries
of the form
name=value
- or
null
signifying that the environment is inherited from the invoking process.
- as an array of entries
of the form
- Returns:
- this octave engine factory after modification.
-
setWorkingDir
public OctaveEngineFactory setWorkingDir(File workingDir)
Setter method forworkingDir
.- Parameters:
workingDir
- the working directory to set ornull
signifying the current directory.- Returns:
- this octave engine factory after modification.
-
setNumThreadsReuse
public OctaveEngineFactory setNumThreadsReuse(int numThreadsReuse)
Sets the number of threads to be reused or-1
which indicates no limit. The default value is 2 but this can be speed optimized depending on the hardware. The number of threads to be created shall be positive or-1
otherwise throwing an exception.- Parameters:
numThreadsReuse
- the number of threads for reuse which is positive or-1
- Returns:
- this octave engine factory after modification.
-
-