Package org.apache.wicket.application
Class ReloadingClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.apache.wicket.application.ReloadingClassLoader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ReloadingClassLoader extends URLClassLoader
Custom ClassLoader that reverses the classloader lookups, and that is able to notify a listener when a class file is changed.- Author:
- Jean-Baptiste Quenot
-
-
Constructor Summary
Constructors Constructor Description ReloadingClassLoader(ClassLoader parent)
Create a new reloading ClassLoader from a list of URLs, and initialize the ModificationWatcher to detect class file modifications
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
addLocation(URL url)
Add the location of a directory containing class filesvoid
destroy()
Remove the ModificationWatcher from the current reloading class loaderstatic void
excludePattern(String pattern)
Exclude a patternstatic Set<URL>
getLocations()
Returns the list of all configured locations of directories containing class filesstatic List<String>
getPatterns()
Returns the list of all configured inclusion or exclusion patternsURL
getResource(String name)
Gets a resource from thisClassLoader.
static void
includePattern(String pattern)
Include a patternClass<?>
loadClass(String name, boolean resolve)
Loads the class from thisClassLoader.
void
setListener(IChangeListener<Class<?>> listener)
Sets the listener that will be notified when a class changesprotected boolean
tryClassHere(String name)
-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, 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, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
ReloadingClassLoader
public ReloadingClassLoader(ClassLoader parent)
Create a new reloading ClassLoader from a list of URLs, and initialize the ModificationWatcher to detect class file modifications- Parameters:
parent
- the parent classloader in case the class file cannot be loaded from the above locations
-
-
Method Detail
-
tryClassHere
protected boolean tryClassHere(String name)
- Parameters:
name
-- Returns:
- true if class if found, false otherwise
-
includePattern
public static void includePattern(String pattern)
Include a pattern- Parameters:
pattern
- the pattern to include
-
excludePattern
public static void excludePattern(String pattern)
Exclude a pattern- Parameters:
pattern
- the pattern to exclude
-
getPatterns
public static List<String> getPatterns()
Returns the list of all configured inclusion or exclusion patterns- Returns:
- list of patterns as String
-
addLocation
public static void addLocation(URL url)
Add the location of a directory containing class files- Parameters:
url
- the URL for the directory
-
getLocations
public static Set<URL> getLocations()
Returns the list of all configured locations of directories containing class files- Returns:
- list of locations as URL
-
getResource
public final URL getResource(String name)
Gets a resource from thisClassLoader. If the resource does not exist in this one, we check the parent. Please note that this is the exact opposite of the
ClassLoader
spec. We use it to work around inconsistent class loaders from third party vendors.- Overrides:
getResource
in classClassLoader
- Parameters:
name
- of resource
-
loadClass
public final Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
Loads the class from thisClassLoader. If the class does not exist in this one, we check the parent. Please note that this is the exact opposite of the
ClassLoader
spec. We use it to load the class from the same classloader as WicketFilter or WicketServlet. When found, the class file is watched for modifications.- Overrides:
loadClass
in classClassLoader
- Parameters:
name
- the name of the classresolve
- iftrue
then resolve the class- Returns:
- the resulting
Class
object - Throws:
ClassNotFoundException
- if the class could not be found
-
setListener
public void setListener(IChangeListener<Class<?>> listener)
Sets the listener that will be notified when a class changes- Parameters:
listener
- the listener to notify upon class change
-
destroy
public void destroy()
Remove the ModificationWatcher from the current reloading class loader
-
-