Class UIMAClassLoader

All Implemented Interfaces:
Closeable, AutoCloseable

public class UIMAClassLoader extends 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 Details

    • MHLC

      public static final 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:
    • 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 Object[] syncLocks
    • isClosed

      private boolean isClosed
  • Constructor Details

    • UIMAClassLoader

      public UIMAClassLoader(String classpath) throws MalformedURLException
      Creates a new UIMAClassLoader based on a classpath string
      Parameters:
      classpath - a classpath string
      Throws:
      MalformedURLException - if a malformed URL has occurred in the classpath string.
    • UIMAClassLoader

      public UIMAClassLoader(URL[] classpath)
      Creates a new UIMAClassLoader based on a classpath URL's
      Parameters:
      classpath - an array of wellformed classpath URL's
    • UIMAClassLoader

      public UIMAClassLoader(URL[] classpath, 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's
      parent - specify the parent of the classloader
    • UIMAClassLoader

      public UIMAClassLoader(String classpath, ClassLoader parent) throws MalformedURLException
      Creates a new UIMAClassLoader based on a classpath string. Also a parent ClassLoader can be specified.
      Parameters:
      classpath - a classpath string
      parent - specify the parent of the classloader
      Throws:
      MalformedURLException - if a malformed URL has occurred in the classpath string.
  • Method Details

    • transformClasspath

      public static URL[] transformClasspath(String classpath) throws 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:
      MalformedURLException - if a malformed URL has occurred in the classpath string.
    • commonInit

      private void commonInit()
    • newInstance

      public static URLClassLoader newInstance(URL[] urls)
      Do not use this factory method - throws unsupportedOperationException
      Parameters:
      urls - -
      Returns:
      -
      Throws:
      UnsupportedOperationException - -
    • newInstance

      public static URLClassLoader newInstance(URL[] urls, ClassLoader parent)
      Do not use this factory method - throws unsupportedOperationException
      Parameters:
      urls - -
      parent - -
      Returns:
      -
      Throws:
      UnsupportedOperationException - -
    • loadClass

      protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
      Overrides:
      loadClass in class ClassLoader
      Throws:
      ClassNotFoundException
    • getResource

      public URL getResource(String name)
      Overrides:
      getResource in class 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 IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class URLClassLoader
      Throws:
      IOException
    • getClassLoadingLockForTesting

      Object getClassLoadingLockForTesting(String aClassName)