public final class LoggingMatlabProxy extends MatlabProxy
MatlabProxy to provide a log of interactions. The data is not altered. This logger is useful
for determining the Java types and structure of data returned from MATLAB.
Object and not overridden, is logged. Entering a
method, exiting a method, and throwing an exception are logged. Method parameters and return values are logged. The
contents of a returned array will be recursively explored and its contents logged. As is convention, all of these
interactions are logged at Level.FINER. If the logging system has not been otherwise configured, then the
ConsoleHandler which prints log messages to the console will not show these log messages as their level is
too low. To configure the ConsoleHandler to show these log messages, call showInConsoleHandler().
MatlabProxy.DisconnectionListener, MatlabProxy.Identifier, MatlabProxy.MatlabThreadCallable<T>, MatlabProxy.MatlabThreadProxy| Constructor and Description |
|---|
LoggingMatlabProxy(MatlabProxy delegateProxy)
Constructs the logging proxy.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDisconnectionListener(MatlabProxy.DisconnectionListener listener)
Adds a disconnection listener that will be notified when this proxy becomes disconnected from MATLAB.
|
boolean |
disconnect()
Disconnects the proxy from MATLAB.
|
void |
eval(String command)
Evaluates a command in MATLAB.
|
void |
exit()
Exits MATLAB.
|
void |
feval(String functionName,
Object... args)
Calls a MATLAB function with the name
functionName, returning the result. |
MatlabProxy.Identifier |
getIdentifier()
Returns the unique identifier for this proxy.
|
Object |
getVariable(String variableName)
Gets the value of
variableName in MATLAB. |
<U> U |
invokeAndWait(MatlabProxy.MatlabThreadCallable<U> callable)
Runs the
callable on MATLAB's main thread and waits for it to return its result. |
boolean |
isConnected()
Whether this proxy is connected to MATLAB.
|
boolean |
isExistingSession()
Whether this proxy is connected to a session of MATLAB that was running previous to the request to create this
proxy.
|
boolean |
isRunningInsideMatlab()
Whether this proxy is running inside of MATLAB.
|
void |
removeDisconnectionListener(MatlabProxy.DisconnectionListener listener)
Removes a disconnection listener.
|
Object[] |
returningEval(String command,
int nargout)
Evaluates a command in MATLAB, returning the result.
|
Object[] |
returningFeval(String functionName,
int nargout,
Object... args)
Calls a MATLAB function with the name
functionName, returning the result. |
void |
setVariable(String variableName,
Object value)
Sets
variableName to value in MATLAB, creating the variable if it does not yet exist. |
static void |
showInConsoleHandler()
Configures the
ConsoleHandler responsible for showing logging records to show the records that are
logged by this proxy. |
String |
toString()
Returns a brief description of this proxy.
|
public LoggingMatlabProxy(MatlabProxy delegateProxy)
MatlabProxy will be delegated to
delegateProxy.delegateProxy - public static void showInConsoleHandler()
ConsoleHandler responsible for showing logging records to show the records that are
logged by this proxy. This behavior is useful if you have not otherwise configured logging in your application.public void eval(String command) throws MatlabInvocationException
MatlabOperationseval('command').command - the command to be evaluated in MATLABMatlabInvocationExceptionpublic Object[] returningEval(String command, int nargout) throws MatlabInvocationException
MatlabOperationseval('command').
nargout. This is equivalent in MATLAB to the number of variables placed on the left hand side of an
expression. For example, in MATLAB the inmem function may be used with either 1, 2, or 3 return values
each resulting in a different behavior:
M = inmem;
[M, X] = inmem;
[M, X, J] = inmem;
The returned Object array will be of length nargout with each return argument placed into the
corresponding array position.
nargout then an exception will be
thrown.command - the command to be evaluated in MATLABnargout - the number of arguments that will be returned from evaluating commandnargoutMatlabInvocationExceptionpublic void feval(String functionName, Object... args) throws MatlabInvocationException
MatlabOperationsfunctionName, returning the result. Arguments to the function may
be provided as args, but are not required if the function needs no arguments.
String will be converted to a MATLAB char array, not a variable name.functionName - the name of the MATLAB function to callargs - the arguments to the functionMatlabInvocationExceptionpublic Object[] returningFeval(String functionName, int nargout, Object... args) throws MatlabInvocationException
MatlabOperationsfunctionName, returning the result. Arguments to the function may
be provided as args, but are not required if the function needs no arguments.
String will be converted to a MATLAB char array, not a variable name.
nargout. This is equivalent in MATLAB to the number of variables placed on the left hand side of an
expression. For example, in MATLAB the inmem function may be used with either 1, 2, or 3 return values
each resulting in a different behavior:
M = inmem;
[M, X] = inmem;
[M, X, J] = inmem;
The returned Object array will be of length nargout with each return argument placed into the
corresponding array position.
nargout then an
exception will be thrown.functionName - the name of the MATLAB function to callnargout - the number of arguments that will be returned by functionNameargs - the arguments to the functionnargoutMatlabInvocationExceptionpublic void setVariable(String variableName, Object value) throws MatlabInvocationException
MatlabOperationsvariableName to value in MATLAB, creating the variable if it does not yet exist.MatlabInvocationExceptionpublic Object getVariable(String variableName) throws MatlabInvocationException
MatlabOperationsvariableName in MATLAB.MatlabInvocationExceptionpublic <U> U invokeAndWait(MatlabProxy.MatlabThreadCallable<U> callable) throws MatlabInvocationException
MatlabProxycallable on MATLAB's main thread and waits for it to return its result. This method allows for
uninterrupted access to MATLAB's main thread between two or more interactions with MATLAB.
callable must be Serializable; it may not be
Remote.invokeAndWait in class MatlabProxyMatlabInvocationExceptionpublic void addDisconnectionListener(MatlabProxy.DisconnectionListener listener)
MatlabProxyaddDisconnectionListener in class MatlabProxypublic void removeDisconnectionListener(MatlabProxy.DisconnectionListener listener)
MatlabProxyremoveDisconnectionListener in class MatlabProxypublic boolean disconnect()
MatlabProxytrue if the proxy is now disconnected,
false otherwise.disconnect in class MatlabProxyMatlabProxy.exit(),
MatlabProxy.isConnected()public boolean isExistingSession()
MatlabProxyisExistingSession in class MatlabProxypublic boolean isRunningInsideMatlab()
MatlabProxyisRunningInsideMatlab in class MatlabProxypublic boolean isConnected()
MatlabProxyfalse are if the proxy has been disconnected via
MatlabProxy.disconnect() or MATLAB has been closed (when running outside MATLAB).isConnected in class MatlabProxyMatlabProxy.disconnect(),
MatlabProxy.exit()public MatlabProxy.Identifier getIdentifier()
MatlabProxygetIdentifier in class MatlabProxypublic void exit()
throws MatlabInvocationException
MatlabProxyeval or feval command will cause MATLAB to
hang indefinitely.exit in class MatlabProxyMatlabInvocationExceptionMatlabProxy.disconnect(),
MatlabProxy.isConnected()public String toString()
MatlabProxytoString in class MatlabProxy