com.acciente.commons.loader
Class ReloadingClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by com.acciente.commons.loader.ReloadingClassLoader

public class ReloadingClassLoader
extends SecureClassLoader

This classloader loads classes retrieved via a class definition loader (aka ClassDefLoader). This class loader uses the methods provided by a ClassDef (a ClassDef is returned by the ClassDefLoader) to determine if the class has been modified and transparently reloads the class into the JVM if the ClassDef reports that the class has been modified.

This class loader also reads dependency information from the ClassDef. When the load of a class, say A, is requested it recursively checks for modificiations to dependent classes. If any of the the dependent classes are modified it first reloads the dependent classes and then proceeds to reload the class A.

Author:
Adinath Raveendra Raj
See Also:
ClassDefLoader, ClassDef

Constructor Summary
ReloadingClassLoader()
          Creates a class loader with no parent class loader, this is expected to cause the system class loader to be used as the parent class loader
ReloadingClassLoader(ClassLoader oParentClassLoader)
          Creates a class loader that delegates to the specified parent class loader
 
Method Summary
 void addClassDefLoader(ClassDefLoader oClassDefLoader)
          Adds a class definition loader to the list of class definition loaders to search
 void addIgnoredClassName(String sIgnoredClassName)
          This method is used to add to the list classnames that should be "ignored" as regards the dependency checking.
 void addIgnoredClassNamePrefix(String sIgnoredClassNamePrefix)
          This method is used to add to list of classname prefixes that should be "ignored" as regards the dependency checking.
protected  Class findClass(String sClassName)
           
 List getClassDefLoaders()
          A list of ClassDefLoaders searched by this class loader.
 Collection getIgnoredClassNamePrefixes()
          Returns the set of classname prefixes that are being "ignored" as regards the dependency checking
 Collection getIgnoredClassNames()
          Returns the set of classnames that are being "ignored" as regards the dependency checking
 InputStream getResourceAsStream(String sResourceName)
          Used to load a resource via this classloader
 Class loadClass(String sClassName, boolean bResolve)
           
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass, getPermissions
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReloadingClassLoader

public ReloadingClassLoader()
Creates a class loader with no parent class loader, this is expected to cause the system class loader to be used as the parent class loader


ReloadingClassLoader

public ReloadingClassLoader(ClassLoader oParentClassLoader)
Creates a class loader that delegates to the specified parent class loader

Parameters:
oParentClassLoader - the parent class loader
Method Detail

addClassDefLoader

public void addClassDefLoader(ClassDefLoader oClassDefLoader)
Adds a class definition loader to the list of class definition loaders to search

Parameters:
oClassDefLoader - an object that implements the class ClassDefLoader interface

getClassDefLoaders

public List getClassDefLoaders()
A list of ClassDefLoaders searched by this class loader.

Returns:
a list containing (in order of search) the classdefloader in use

addIgnoredClassName

public void addIgnoredClassName(String sIgnoredClassName)
This method is used to add to the list classnames that should be "ignored" as regards the dependency checking. By "ignored" is meant the following: If class A depends on class B, and if class B changes, then if class B is on the list of classes to be "ignored" then the behavior is identical to that if class A had no dependency on class B.

Parameters:
sIgnoredClassName - a string representing a fully qualified classname

addIgnoredClassNamePrefix

public void addIgnoredClassNamePrefix(String sIgnoredClassNamePrefix)
This method is used to add to list of classname prefixes that should be "ignored" as regards the dependency checking. For example specifying "com.foo.bar." will cause all classesname starting with com.foo.bar. package to be ignored. By "ignored" is meant the following: If class A depends on class B, and if class B changes, then if class B is on the list of classes to be "ignored" then the behavior is identical to if class A had no dependency on class B

Parameters:
sIgnoredClassNamePrefix - a string representing the prefix of one or more fully qualified classnames

getIgnoredClassNames

public Collection getIgnoredClassNames()
Returns the set of classnames that are being "ignored" as regards the dependency checking

Returns:
a set of strings representing classnames that should be ignored by the dependency checker.

getIgnoredClassNamePrefixes

public Collection getIgnoredClassNamePrefixes()
Returns the set of classname prefixes that are being "ignored" as regards the dependency checking

Returns:
a set of strings representing classname prefixes that should be ignored by the dependency checker.

getResourceAsStream

public InputStream getResourceAsStream(String sResourceName)
Used to load a resource via this classloader

Overrides:
getResourceAsStream in class ClassLoader
Returns:
an input stream, or null if the resource could not be loaded

loadClass

public Class loadClass(String sClassName,
                       boolean bResolve)
                throws ClassNotFoundException
Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

findClass

protected Class findClass(String sClassName)
                   throws ClassNotFoundException
Overrides:
findClass in class ClassLoader
Throws:
ClassNotFoundException


Copyright © 2008-2013 Acciente, LLC. All Rights Reserved.