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 anOctaveEngineif 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[]argsArrayThe array of arguments of the octave engines created.CharsetcharsetThe character set used to transform input stream , output stream and error stream for 'octave process'.private String[]environmentAn array of strings of the formname=valuerepresenting the environment, i.e. the set of environment variables ornull.private WritererrWriterThe error writer for the octave process.private intnumThreadsReuseThe number of threads to be reused or-1if there is no limit.private WriteroctaveInputLogIf this is notnull, the octave engine created writes the output to that log writer also.private StringoctaveProgramCmdThe command which determines the octave executable ifoctaveProgramFileisnulland if the propertyPROPERTY_EXECUTABLEis not set.private FileoctaveProgramFileThe file containing the octave program or isnull.static StringPROPERTY_EXECUTABLEThe custom system property which determines where the executable is found ifoctaveProgramFileis not set.private FileworkingDirThe 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 OctaveEnginegetScriptEngine()Returns a script engine with the parameters set for this factory.OctaveEngineFactorysetArgsArray(String[] argsArray)Sets an array of argumentsargsArrayused when creating anOctaveEngine.OctaveEngineFactorysetCharset(Charset charset)Sets the encoding of input, output and error stream of the 'octave process'.OctaveEngineFactorysetEnvironment(String[] environment)Setter method forenvironment.OctaveEngineFactorysetErrorWriter(Writer errWriter)Setter method forerrWriter.OctaveEngineFactorysetNumThreadsReuse(int numThreadsReuse)Sets the number of threads to be reused or-1which indicates no limit.OctaveEngineFactorysetOctaveInputLog(Writer octaveInputLog)Setter method foroctaveInputLog.OctaveEngineFactorysetOctaveProgramCmd(String octaveProgramCmd)Setter method foroctaveProgramCmd.OctaveEngineFactorysetOctaveProgramFile(File octaveProgramFile)Setter method foroctaveProgramFile.OctaveEngineFactorysetWorkingDir(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 ifoctaveProgramFileis not set. A custom property is set when invoking the runtime with the option-DFor examplejava -Deu.simuline.octave.executable=myoctave Applicationruns classApplicationsetting the system propertyeu.simuline.octave.executableto- 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_8which 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 ifoctaveProgramFileisnulland if the propertyPROPERTY_EXECUTABLEis 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-fileprevents octave from reading the initialization files~/.octaverc,.octavercand site-wideoctaverc.
--silent: If not set this, octave's greeting message causes an exception. Option--no-init-filemakes the result independent of user input, whereas--no-init-fileand--no-site-filemakes it independent of initialization files. Since this is used to create scripting engines, line editing and history seem superfluous and so--no-line-editingand--no-historyseem appropriate. Note that--no-init-fileand--no-site-filemay be appropriate or not. Instead of combining--no-init-fileand--no-site-fileequivalently 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=valuerepresenting 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-1if 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 ornullif 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, ifoctaveProgramFileisnulland if the propertyPROPERTY_EXECUTABLEis not set.- Parameters:
octaveProgramCmd- the octave program executable to set- Returns:
- this octave engine factory after modification.
- Throws:
NullPointerException- ifoctaveProgramCmdisnull.
-
setArgsArray
public OctaveEngineFactory setArgsArray(String[] argsArray)
Sets an array of argumentsargsArrayused when creating anOctaveEngine. The validity of the argument string is not proved. Note that subsequent changes on the arrayargsArraydo 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- ifargsArrayisnullor contains anullentry.
-
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_8so this method may be used rarely.- Parameters:
charset- the new charset.- Returns:
- this octave engine factory after modification.
- Throws:
NullPointerException- ifcharsetisnull.
-
setEnvironment
public OctaveEngineFactory setEnvironment(String[] environment)
Setter method forenvironment. Note that subsequent changes on the arrayenvironmentdo 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
nullsignifying 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 ornullsignifying 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-1which 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-1otherwise throwing an exception.- Parameters:
numThreadsReuse- the number of threads for reuse which is positive or-1- Returns:
- this octave engine factory after modification.
-
-