Class MatlabRMIClassLoaderSpi


  • public class MatlabRMIClassLoaderSpi
    extends java.rmi.server.RMIClassLoaderSpi
    Internal Use Only

    This class must be public so that it can be created via reflection by RemoteClassLoader. If it were package private it would result in an IllegalAccessError because only classes in the same package as a package private class may construct it (even via reflection). It has been placed in the matlabcontrol.internal package to make it clear it is not intended for use by users of matlabcontrol.

    A custom service provider for the RMI class loader. Allows for loading classes sent from the external JVM and providing annotations so that the external JVM may load classes defined only in the MATLAB JVM. Loading classes from the external JVM could be accomplished by setting java.rmi.server.codebase property in the external JVM but that could interfere with other uses of RMI in the application. There is no way to always sending the correct annotations without this custom rmi class loader spi. While the java.rmi.server.codebase property could be set in the MATLAB JVM, the property is checked only at load time. This would mean that class definitions added dynamically with javaaddpath could not be sent.
    Since:
    4.0.0
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getClassAnnotation​(java.lang.Class<?> clazz)


      The returned annotation becomes the codebase argument in loadClass(java.lang.String, java.lang.String, java.lang.ClassLoader) when the RMIClassLoaderSpi in the receiving JVM attempts to load clazz.
      java.lang.ClassLoader getClassLoader​(java.lang.String codebase)  
      java.lang.Class<?> loadClass​(java.lang.String codebase, java.lang.String name, java.lang.ClassLoader defaultLoader)  
      java.lang.Class<?> loadProxyClass​(java.lang.String codebase, java.lang.String[] interfaces, java.lang.ClassLoader defaultLoader)  
      static void setCodebase​(java.lang.String remoteCodebase)
      Sets the codebase of the currently connected external JVM.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MatlabRMIClassLoaderSpi

        public MatlabRMIClassLoaderSpi()
    • Method Detail

      • setCodebase

        public static void setCodebase​(java.lang.String remoteCodebase)
        Sets the codebase of the currently connected external JVM. This should be called only once per connection to an external JVM and should occur before users of the API can send objects over RMI.
        Parameters:
        remoteCodebase -
      • loadClass

        public java.lang.Class<?> loadClass​(java.lang.String codebase,
                                            java.lang.String name,
                                            java.lang.ClassLoader defaultLoader)
                                     throws java.net.MalformedURLException,
                                            java.lang.ClassNotFoundException
        Specified by:
        loadClass in class java.rmi.server.RMIClassLoaderSpi
        Throws:
        java.net.MalformedURLException
        java.lang.ClassNotFoundException
      • loadProxyClass

        public java.lang.Class<?> loadProxyClass​(java.lang.String codebase,
                                                 java.lang.String[] interfaces,
                                                 java.lang.ClassLoader defaultLoader)
                                          throws java.net.MalformedURLException,
                                                 java.lang.ClassNotFoundException
        Specified by:
        loadProxyClass in class java.rmi.server.RMIClassLoaderSpi
        Throws:
        java.net.MalformedURLException
        java.lang.ClassNotFoundException
      • getClassLoader

        public java.lang.ClassLoader getClassLoader​(java.lang.String codebase)
                                             throws java.net.MalformedURLException
        Specified by:
        getClassLoader in class java.rmi.server.RMIClassLoaderSpi
        Throws:
        java.net.MalformedURLException
      • getClassAnnotation

        public java.lang.String getClassAnnotation​(java.lang.Class<?> clazz)


        The returned annotation becomes the codebase argument in loadClass(java.lang.String, java.lang.String, java.lang.ClassLoader) when the RMIClassLoaderSpi in the receiving JVM attempts to load clazz. This allows for classes defined in MATLAB but not in the receiving JVM to find and load the class definition.
        Specified by:
        getClassAnnotation in class java.rmi.server.RMIClassLoaderSpi
        Parameters:
        clazz -
        Returns: