org.openmrs.util
Class OpenmrsClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.openmrs.util.OpenmrsClassLoader

public class OpenmrsClassLoader
extends java.net.URLClassLoader

This classloader knows about the current ModuleClassLoaders and will attempt to load classes from them if needed


Constructor Summary
OpenmrsClassLoader()
          Normal constructor.
OpenmrsClassLoader(java.lang.ClassLoader parent)
          Creates the instance for the OpenmrsClassLoader
 
Method Summary
protected static void clearReferences()
          This clears any references this classloader might have that will prevent garbage collection.
static void deleteOldLibCaches(java.io.File libCacheFolder)
          Deletes the old lib cache folders that might not have been deleted when OpenMRS closed
static void destroyInstance()
          Destroy the current instance of the classloader.
static java.net.URL expandURL(java.net.URL result, java.io.File folder)
          Expand the given URL into the given folder
 java.net.URL findResource(java.lang.String name)
           
 java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
           
static void flushInstance()
          All objects depending on the old classloader should be restarted here Should be called after destoryInstance() and after the service is restarted
static OpenmrsClassLoader getInstance()
          Get the static/singular instance of the module class loader
static java.io.File getLibCacheFolder()
          Get the temporary "work" directory for expanded jar files
 java.io.InputStream getResourceAsStream(java.lang.String file)
          Searches all known module classloaders first, then parent classloaders
 java.util.Enumeration<java.net.URL> getResources(java.lang.String packageName)
          Searches all known module classloaders first, then parent classloaders
 java.lang.Class<?> loadClass(java.lang.String name, boolean resolve)
           
protected static boolean loadedByThisOrChild(java.lang.Class<?> clazz)
          Determine whether a class was loaded by this class loader or one of its child class loaders.
protected static void nullInstance(java.lang.Object instance)
          Used by clearReferences() upon application close.
static void onShutdown()
           
static void restoreState()
          This method should be called after restoring the instance
static void saveState()
          This method should be called before destroying the instance
 java.lang.String toString()
           
 
Methods inherited from class java.net.URLClassLoader
addURL, definePackage, findClass, getPermissions, getURLs, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResource, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OpenmrsClassLoader

public OpenmrsClassLoader(java.lang.ClassLoader parent)
Creates the instance for the OpenmrsClassLoader


OpenmrsClassLoader

public OpenmrsClassLoader()
Normal constructor. Sets this class as the parent classloader

Method Detail

getInstance

public static OpenmrsClassLoader getInstance()
Get the static/singular instance of the module class loader

Returns:
OpenmrsClassLoader

loadClass

public java.lang.Class<?> loadClass(java.lang.String name,
                                    boolean resolve)
                             throws java.lang.ClassNotFoundException
Overrides:
loadClass in class java.lang.ClassLoader
Throws:
java.lang.ClassNotFoundException
See Also:
ClassLoader.loadClass(java.lang.String, boolean)

findResource

public java.net.URL findResource(java.lang.String name)
Overrides:
findResource in class java.net.URLClassLoader
See Also:
URLClassLoader.findResource(java.lang.String)

findResources

public java.util.Enumeration<java.net.URL> findResources(java.lang.String name)
                                                  throws java.io.IOException
Overrides:
findResources in class java.net.URLClassLoader
Throws:
java.io.IOException
See Also:
URLClassLoader.findResources(java.lang.String)

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String file)
Searches all known module classloaders first, then parent classloaders

Overrides:
getResourceAsStream in class java.lang.ClassLoader
See Also:
ClassLoader.getResourceAsStream(java.lang.String)

getResources

public java.util.Enumeration<java.net.URL> getResources(java.lang.String packageName)
                                                 throws java.io.IOException
Searches all known module classloaders first, then parent classloaders

Overrides:
getResources in class java.lang.ClassLoader
Throws:
java.io.IOException
See Also:
ClassLoader.getResources(java.lang.String)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

destroyInstance

public static void destroyInstance()
Destroy the current instance of the classloader. Note**: After calling this and after the new service is set up, All classes using this instance should be flushed. This would allow all java classes that were loaded by the old instance variable to be gc'd and modules to load in new java classes

See Also:
flushInstance()

onShutdown

public static void onShutdown()

clearReferences

protected static void clearReferences()
This clears any references this classloader might have that will prevent garbage collection.

Borrowed from Tomcat's WebappClassLoader#clearReferences() (not javadoc linked intentionally)
The only difference between this and Tomcat's implementation is that this one only acts on openmrs objects and also clears out static java.* packages. Tomcat acts on all objects and does not clear our static java.* objects.

Since:
1.5

nullInstance

protected static void nullInstance(java.lang.Object instance)
Used by clearReferences() upon application close.

Borrowed from Tomcat's WebappClassLoader.

Parameters:
instance - the object whose fields need to be nulled out

loadedByThisOrChild

protected static boolean loadedByThisOrChild(java.lang.Class<?> clazz)
Determine whether a class was loaded by this class loader or one of its child class loaders.

Borrowed from Tomcat's WebappClassLoader


saveState

public static void saveState()
This method should be called before destroying the instance

See Also:
destroyInstance()

restoreState

public static void restoreState()
This method should be called after restoring the instance

See Also:
destroyInstance(), saveState()

flushInstance

public static void flushInstance()
All objects depending on the old classloader should be restarted here Should be called after destoryInstance() and after the service is restarted

See Also:
destroyInstance()

getLibCacheFolder

public static java.io.File getLibCacheFolder()
Get the temporary "work" directory for expanded jar files

Returns:
temporary location for storing the libraries

deleteOldLibCaches

public static void deleteOldLibCaches(java.io.File libCacheFolder)
Deletes the old lib cache folders that might not have been deleted when OpenMRS closed

Parameters:
libCacheFolder -

expandURL

public static java.net.URL expandURL(java.net.URL result,
                                     java.io.File folder)
Expand the given URL into the given folder

Parameters:
result - URL of the file to expand
folder - File (directory) to place the expanded file
Returns:
the URL at the expanded location

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change