Package matlabcontrol

Class LoggingMatlabProxy

  • All Implemented Interfaces:
    MatlabOperations

    public final class LoggingMatlabProxy
    extends MatlabProxy
    Wraps around a 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.

    Interaction with all methods, except those defined in 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().

    This class is unconditionally thread-safe.
    Since:
    4.1.0
    • Constructor Detail

      • LoggingMatlabProxy

        public LoggingMatlabProxy​(MatlabProxy delegateProxy)
        Constructs the logging proxy. All methods defined in MatlabProxy will be delegated to delegateProxy.
        Parameters:
        delegateProxy -
    • Method Detail

      • showInConsoleHandler

        public static void showInConsoleHandler()
        Configures the 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.
      • returningEval

        public java.lang.Object[] returningEval​(java.lang.String command,
                                                int nargout)
                                         throws MatlabInvocationException
        Description copied from interface: MatlabOperations
        Evaluates a command in MATLAB, returning the result. This is equivalent to MATLAB's eval('command').

        In order for the result of this command to be returned the number of arguments to be returned must be specified by 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.

        If the command cannot return the number of arguments specified by nargout then an exception will be thrown.
        Parameters:
        command - the command to be evaluated in MATLAB
        nargout - the number of arguments that will be returned from evaluating command
        Returns:
        result of MATLAB command, the length of the array will be nargout
        Throws:
        MatlabInvocationException
      • feval

        public void feval​(java.lang.String functionName,
                          java.lang.Object... args)
                   throws MatlabInvocationException
        Description copied from interface: MatlabOperations
        Calls a MATLAB function with the name functionName, returning the result. Arguments to the function may be provided as args, but are not required if the function needs no arguments.

        The function arguments will be converted into MATLAB equivalents as appropriate. Importantly, this means that a String will be converted to a MATLAB char array, not a variable name.
        Parameters:
        functionName - the name of the MATLAB function to call
        args - the arguments to the function
        Throws:
        MatlabInvocationException
      • returningFeval

        public java.lang.Object[] returningFeval​(java.lang.String functionName,
                                                 int nargout,
                                                 java.lang.Object... args)
                                          throws MatlabInvocationException
        Description copied from interface: MatlabOperations
        Calls a MATLAB function with the name functionName, returning the result. Arguments to the function may be provided as args, but are not required if the function needs no arguments.

        The function arguments will be converted into MATLAB equivalents as appropriate. Importantly, this means that a String will be converted to a MATLAB char array, not a variable name.

        In order for the result of this function to be returned the number of arguments to be returned must be specified by 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.

        If the function is not capable of returning the number of arguments specified by nargout then an exception will be thrown.
        Parameters:
        functionName - the name of the MATLAB function to call
        nargout - the number of arguments that will be returned by functionName
        args - the arguments to the function
        Returns:
        result of MATLAB function, the length of the array will be nargout
        Throws:
        MatlabInvocationException
      • disconnect

        public boolean disconnect()
        Description copied from class: MatlabProxy
        Disconnects the proxy from MATLAB. MATLAB will not exit. After disconnecting, any method sent to MATLAB will throw an exception. A proxy cannot be reconnected. Returns true if the proxy is now disconnected, false otherwise.
        Specified by:
        disconnect in class MatlabProxy
        Returns:
        if disconnected
        See Also:
        MatlabProxy.exit(), MatlabProxy.isConnected()
      • isExistingSession

        public boolean isExistingSession()
        Description copied from class: MatlabProxy
        Whether this proxy is connected to a session of MATLAB that was running previous to the request to create this proxy.
        Overrides:
        isExistingSession in class MatlabProxy
        Returns:
        if existing session
      • isRunningInsideMatlab

        public boolean isRunningInsideMatlab()
        Description copied from class: MatlabProxy
        Whether this proxy is running inside of MATLAB.
        Specified by:
        isRunningInsideMatlab in class MatlabProxy
        Returns:
      • toString

        public java.lang.String toString()
        Description copied from class: MatlabProxy
        Returns a brief description of this proxy. The exact details of this representation are unspecified and are subject to change.
        Overrides:
        toString in class MatlabProxy