MatlabProxyFactoryOptions.Builder¶
-
public static class
Builder
¶ Creates instances of
MatlabProxyFactoryOptions
. Any and all of these properties may be left unset, if so then a default will be used. Depending on how the factory operates, not all properties may be used. Currently all properties are used only when running outside MATLAB, but future releases may add additional options. Calls on this class may be chained together to easily create factory options. Example usage:MatlabProxyFactoryOptions options = new MatlabProxyFactoryOptions.Builder() .setHidden(true) .setProxyTimeout(30000L) .build();
This class is unconditionally thread-safe.
Author: Joshua Kaplan
Methods¶
build¶
-
public final MatlabProxyFactoryOptions
build
()¶ Builds a
MatlabProxyFactoryOptions
instance.Returns: factory options
setJavaDebugger¶
-
public final Builder
setJavaDebugger
(int portnumber)¶ Sets whether to enable use of the Java debugger on the MATLAB session using port
portnumber
. Theportnumber
may be in the range0-65535
so long as it is not reserved or otherwise in use. By default the Java debugger is not enabled.Parameters: - portnumber –
Throws: - IllegalArgumentException – if
portnumber
is not in the range0-65535
setLicenseFile¶
-
public final Builder
setLicenseFile
(String licenseFile)¶ Sets the license file used by MATLAB. By default no license file is specified. On Linux and OS X
licenseFile
may have the formport@host
or a colon-separated list of license filenames. On WindowslicenseFile
may have the formport@host
. Setting this option causes theLM_LICENSE_FILE
andMLM_LICENSE_FILE
environment variables to be ignored. The validity oflicenseFile
is not checked by matlabcontrol.Parameters: - licenseFile –
setLogFile¶
setMatlabLocation¶
-
public final Builder
setMatlabLocation
(String matlabLocation)¶ Sets the location of the MATLAB executable or script that will launch MATLAB. If the value set cannot be successfully used to launch MATLAB, an exception will be thrown when attempting to create a proxy. The absolute path to the MATLAB executable can be determined by running MATLAB. On OS X or Linux, evaluate
[matlabroot '/bin/matlab']
in the Command Window. On Windows, evaluate[matlabroot '/bin/matlab.exe']
in the Command Window. The location provided does not have to be an absolute path so long as the operating system can resolve the path. Windows Locations relative to the following will be understood:- The current working directory
- The
Windows
directory only (no subdirectories are searched) - The
Windows\System32
directory - Directories listed in the
PATH
environment variable - App Paths defined in the registry with key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
By default on Windows, MATLAB places an App Path entry in the registry so that
matlab
can be used to launch MATLAB. If this property is not set, this App Path entry will be used. OS X Locations relative to the following will be understood:- The current working directory
- Directories listed in the
PATH
environment variable
On OS X, MATLAB is installed in
/Applications/
as an application bundle. If this property is not set, the executable inside of the application bundle will be used. Linux Locations relative to the following will be understood:- The current working directory
- Directories listed in the
PATH
environment variable
During the installation process on Linux, MATLAB can create a symbolic link named
matlab
that can be used to launch MATLAB. If this property is not set, this symbolic link will be used.Parameters: - matlabLocation –
setMatlabStartingDirectory¶
-
public final Builder
setMatlabStartingDirectory
(File dir)¶ Sets the starting directory for MATLAB.
Parameters: - dir –
Throws: - IllegalArgumentException – if
dir
does not exist or is not a directory - NullPointerException – if
dir
isnull
setPort¶
-
public final Builder
setPort
(int port)¶ Sets the port matlabcontrol uses to communicate with MATLAB. By default port
2100
is used. The port value may not be negative. It is recommended to be in the range of1024
to49151
, but this range is not enforced. The port should be otherwise unused; however, any number ofMatlabProxyFactory
instances (even those running in completely separate applications) may use the same port. AMatlabProxyFactory
will only be able to connect to a previously controlled running session that was started by a factory using the sameport
.Parameters: - port –
Throws: - IllegalArgumentException – if port is negative
setProxyTimeout¶
-
public final Builder
setProxyTimeout
(long timeout)¶ Sets the amount of time in milliseconds to wait for a proxy to be created when requested via the blocking method
MatlabProxyFactory.getProxy()
. By default this property is set to180000
milliseconds.Parameters: - timeout –
Throws: - IllegalArgumentException – if timeout is negative
setUsePreviouslyControlledSession¶
-
public final Builder
setUsePreviouslyControlledSession
(boolean usePreviouslyControlled)¶ Sets whether the factory should attempt to create a proxy that is connected to a running session of MATLAB. By default this property is set to
false
. When this property istrue
all options which configure MATLAB such as being hidden or logging are ignored. The only criterion used is whether a session of MATLAB is available for connection. In order for the factory to connect to the session of MATLAB, it must know about the session. This will be the case if a factory started the session of MATLAB and that factory was configured to use the same port as specified bysetPort(int)
(or both are using the default port). The factory will only connect to a session that does not currently have a proxy controlling it from outside of MATLAB. To determine if the proxy created is connected to an existing session of MATLAB callMatlabProxy.isExistingSession()
. You may wish to clear MATLAB’s environment usingclear
. Doing so will not in anyway interfere with matlabcontrol (including executingclear java
). If a running session of MATLAB previously loaded classes defined in the controlling application, issues can arise. If your application does send to MATLAB or retrieve from MATLAB customjava.io.Serializable
orjava.rmi.Remote
classes then these issues do not apply. MATLAB sessions launched by matlabcontrol are able to load classes defined in the controlling application. When an existing session of MATLAB is connected to by a newly controlling application it will now be able to load classes defined by the newly controlling application but not the previous one. Several problems may arise due to this behavior. If an attempt is made to use a class defined in a previously controlling session that was not loaded while the application was controlling MATLAB then it will fail with aClassNotFoundException
if it is not also defined in the newly controlling application. If the class is defined it will fail to load it if the serializable definition is not compatible. A similar issue is if the newly controlling application attempts to send to MATLAB an instance of a class that was also defined by the previously controlling application but the serializable definition is not compatible. These above issues can easily be encountered when developing an application while changingSerializable
orRemote
classes and using the same session of MATLAB repeatedly. This will particularly be the case if the classes do not define aserialVersionUID
. If multiple instances of the same application do not vary in their definition ofSerializable
andRemote
classes then connecting to a previously controlled session of MATLAB will not cause any issues in this regard.Parameters: - usePreviouslyControlled –