Package matlabcontrol.internal
Class MatlabRMIClassLoaderSpi
- java.lang.Object
-
- java.rmi.server.RMIClassLoaderSpi
-
- matlabcontrol.internal.MatlabRMIClassLoaderSpi
-
public class MatlabRMIClassLoaderSpi extends java.rmi.server.RMIClassLoaderSpiInternal Use Only
This class must be public so that it can be created via reflection byRemoteClassLoader. If it were package private it would result in anIllegalAccessErrorbecause only classes in the same package as a package private class may construct it (even via reflection). It has been placed in thematlabcontrol.internalpackage 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 settingjava.rmi.server.codebaseproperty 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 thejava.rmi.server.codebaseproperty could be set in the MATLAB JVM, the property is checked only at load time. This would mean that class definitions added dynamically withjavaaddpathcould not be sent.- Since:
- 4.0.0
-
-
Constructor Summary
Constructors Constructor Description MatlabRMIClassLoaderSpi()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetClassAnnotation(java.lang.Class<?> clazz)
The returned annotation becomes thecodebaseargument inloadClass(java.lang.String, java.lang.String, java.lang.ClassLoader)when theRMIClassLoaderSpiin the receiving JVM attempts to loadclazz.java.lang.ClassLoadergetClassLoader(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 voidsetCodebase(java.lang.String remoteCodebase)Sets the codebase of the currently connected external JVM.
-
-
-
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:
loadClassin classjava.rmi.server.RMIClassLoaderSpi- Throws:
java.net.MalformedURLExceptionjava.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:
loadProxyClassin classjava.rmi.server.RMIClassLoaderSpi- Throws:
java.net.MalformedURLExceptionjava.lang.ClassNotFoundException
-
getClassLoader
public java.lang.ClassLoader getClassLoader(java.lang.String codebase) throws java.net.MalformedURLException- Specified by:
getClassLoaderin classjava.rmi.server.RMIClassLoaderSpi- Throws:
java.net.MalformedURLException
-
getClassAnnotation
public java.lang.String getClassAnnotation(java.lang.Class<?> clazz)
The returned annotation becomes thecodebaseargument inloadClass(java.lang.String, java.lang.String, java.lang.ClassLoader)when theRMIClassLoaderSpiin the receiving JVM attempts to loadclazz. This allows for classes defined in MATLAB but not in the receiving JVM to find and load the class definition.- Specified by:
getClassAnnotationin classjava.rmi.server.RMIClassLoaderSpi- Parameters:
clazz-- Returns:
-
-