Package org.apache.uima.internal.util
Class UIMAClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.apache.uima.internal.util.UIMAClassLoader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class UIMAClassLoader extends java.net.URLClassLoader
UIMAClassLoader is used as extension ClassLoader for UIMA to load additional components like annotators and resources. The classpath of the classloader is specified as string. The strategy for this ClassLoader tries to load the class itself before the classloading is delegated to the application class loader. This loader supports loading a special class "MethodHandlesLookup" from org.apache.uima.cas.impl.MethodHandlesLookup This is loaded from a byte string in order to have the defaulting mechanism for MethodHandlesLookup default to this class loaders context.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
isClosed
(package private) static byte[]
methodHandlesLookupClass
This is the byte array that defines the class org.apache.uima.cas.impl.MethodHandlesLookup, obtained by converting the .class file to a hex byte string.static java.lang.String
MHLC
This is a trick to allow loading the same class multiple times in different UIMAClassLoaders https://issues.apache.org/jira/browse/UIMA-5030private static int
nbrLocks
locks for loading more than 1 class at a time (on different threads) no more than the total number of cores, rounded up to pwr of 2private java.lang.Object[]
syncLocks
-
Constructor Summary
Constructors Constructor Description UIMAClassLoader(java.lang.String classpath)
Creates a new UIMAClassLoader based on a classpath stringUIMAClassLoader(java.lang.String classpath, java.lang.ClassLoader parent)
Creates a new UIMAClassLoader based on a classpath string.UIMAClassLoader(java.net.URL[] classpath)
Creates a new UIMAClassLoader based on a classpath URL'sUIMAClassLoader(java.net.URL[] classpath, java.lang.ClassLoader parent)
Creates a new UIMAClassLoader based on a classpath URL's.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
private void
commonInit()
(package private) java.lang.Object
getClassLoadingLockForTesting(java.lang.String aClassName)
java.net.URL
getResource(java.lang.String name)
boolean
isClosed()
The UIMA Class Loader extends URLClassLoader.protected java.lang.Class<?>
loadClass(java.lang.String name, boolean resolve)
static java.net.URLClassLoader
newInstance(java.net.URL[] urls)
Do not use this factory method - throws unsupportedOperationExceptionstatic java.net.URLClassLoader
newInstance(java.net.URL[] urls, java.lang.ClassLoader parent)
Do not use this factory method - throws unsupportedOperationExceptionstatic java.net.URL[]
transformClasspath(java.lang.String classpath)
Transforms the string classpath to a URL array based classpath.-
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs
-
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getClassLoadingLock, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, registerAsParallelCapable, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Field Detail
-
MHLC
public static final java.lang.String MHLC
This is a trick to allow loading the same class multiple times in different UIMAClassLoaders https://issues.apache.org/jira/browse/UIMA-5030- See Also:
- Constant Field Values
-
methodHandlesLookupClass
static byte[] methodHandlesLookupClass
This is the byte array that defines the class org.apache.uima.cas.impl.MethodHandlesLookup, obtained by converting the .class file to a hex byte string.
-
nbrLocks
private static final int nbrLocks
locks for loading more than 1 class at a time (on different threads) no more than the total number of cores, rounded up to pwr of 2
-
syncLocks
private final java.lang.Object[] syncLocks
-
isClosed
private boolean isClosed
-
-
Constructor Detail
-
UIMAClassLoader
public UIMAClassLoader(java.lang.String classpath) throws java.net.MalformedURLException
Creates a new UIMAClassLoader based on a classpath string- Parameters:
classpath
- a classpath string- Throws:
java.net.MalformedURLException
- if a malformed URL has occurred in the classpath string.
-
UIMAClassLoader
public UIMAClassLoader(java.net.URL[] classpath)
Creates a new UIMAClassLoader based on a classpath URL's- Parameters:
classpath
- an array of wellformed classpath URL's
-
UIMAClassLoader
public UIMAClassLoader(java.net.URL[] classpath, java.lang.ClassLoader parent)
Creates a new UIMAClassLoader based on a classpath URL's. Also a parent ClassLoader can be specified.- Parameters:
classpath
- an array of wellformed classpath URL'sparent
- specify the parent of the classloader
-
UIMAClassLoader
public UIMAClassLoader(java.lang.String classpath, java.lang.ClassLoader parent) throws java.net.MalformedURLException
Creates a new UIMAClassLoader based on a classpath string. Also a parent ClassLoader can be specified.- Parameters:
classpath
- a classpath stringparent
- specify the parent of the classloader- Throws:
java.net.MalformedURLException
- if a malformed URL has occurred in the classpath string.
-
-
Method Detail
-
transformClasspath
public static java.net.URL[] transformClasspath(java.lang.String classpath) throws java.net.MalformedURLException
Transforms the string classpath to a URL array based classpath. The classpath string must be separated with the filesystem path separator.- Parameters:
classpath
- a classpath string- Returns:
- URL[] array of wellformed URL's
- Throws:
java.net.MalformedURLException
- if a malformed URL has occurred in the classpath string.
-
commonInit
private void commonInit()
-
newInstance
public static java.net.URLClassLoader newInstance(java.net.URL[] urls)
Do not use this factory method - throws unsupportedOperationException- Parameters:
urls
- -- Returns:
- -
- Throws:
java.lang.UnsupportedOperationException
- -
-
newInstance
public static java.net.URLClassLoader newInstance(java.net.URL[] urls, java.lang.ClassLoader parent)
Do not use this factory method - throws unsupportedOperationException- Parameters:
urls
- -parent
- -- Returns:
- -
- Throws:
java.lang.UnsupportedOperationException
- -
-
loadClass
protected java.lang.Class<?> loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
- Overrides:
loadClass
in classjava.lang.ClassLoader
- Throws:
java.lang.ClassNotFoundException
-
getResource
public java.net.URL getResource(java.lang.String name)
- Overrides:
getResource
in classjava.lang.ClassLoader
-
isClosed
public boolean isClosed()
The UIMA Class Loader extends URLClassLoader. This kind of classloader supports the close() method. When this class loader is closed, it remembers this.- Returns:
- true if this class loader has been closed.
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.net.URLClassLoader
- Throws:
java.io.IOException
-
getClassLoadingLockForTesting
java.lang.Object getClassLoadingLockForTesting(java.lang.String aClassName)
-
-