Class WatchResourcesClassLoader
- java.lang.Object
-
- java.lang.ClassLoader
-
- java.security.SecureClassLoader
-
- java.net.URLClassLoader
-
- org.hotswap.agent.util.classloader.WatchResourcesClassLoader
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class WatchResourcesClassLoader extends URLClassLoader
Special URL classloader to get only changed resources from URL. Use this classloader to support watchResources property. This classloader checks if the resource was modified after application startup and in that case delegates getResource()/getResources() to custom URL classloader. Otherwise returns null or resource from paren classloader (depending on searchParent property).- Author:
- Jiri Bubnik
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWatchResourcesClassLoader.UrlOnlyClassLoaderHelper classloader to get resources from list of urls only.
-
Constructor Summary
Constructors Constructor Description WatchResourcesClassLoader()WatchResourcesClassLoader(boolean searchParent)WatchResourcesClassLoader(ClassLoader classLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetClasspath()Support for classpath builder on Tomcat.URLgetResource(String name)Returns URL only if the resource is found in changedURL and was actually changed after instantiation of this classloader.InputStreamgetResourceAsStream(String name)Enumeration<URL>getResources(String name)Returns only a single instance of the changed resource.voidinitExtraPath(URL[] extraPath)Configure new instance with urls and watcher service.voidinitWatchResources(URL[] watchResources, Watcher watcher)Configure new instance with urls and watcher service.booleanisResourceChanged(URL url)Check if the resource was changed after this classloader instantiaton.voidsetSearchParent(boolean searchParent)-
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, 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, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
-
-
-
-
Constructor Detail
-
WatchResourcesClassLoader
public WatchResourcesClassLoader()
-
WatchResourcesClassLoader
public WatchResourcesClassLoader(boolean searchParent)
-
WatchResourcesClassLoader
public WatchResourcesClassLoader(ClassLoader classLoader)
-
-
Method Detail
-
setSearchParent
public void setSearchParent(boolean searchParent)
-
initExtraPath
public void initExtraPath(URL[] extraPath)
Configure new instance with urls and watcher service.- Parameters:
extraPath- the URLs from which to load resources
-
initWatchResources
public void initWatchResources(URL[] watchResources, Watcher watcher)
Configure new instance with urls and watcher service.- Parameters:
watchResources- the URLs from which to load resourceswatcher- watcher service to register watch events
-
isResourceChanged
public boolean isResourceChanged(URL url)
Check if the resource was changed after this classloader instantiaton.- Parameters:
url- full URL of the file- Returns:
- true if was changed after instantiation
-
getResource
public URL getResource(String name)
Returns URL only if the resource is found in changedURL and was actually changed after instantiation of this classloader.- Overrides:
getResourcein classClassLoader
-
getResourceAsStream
public InputStream getResourceAsStream(String name)
- Overrides:
getResourceAsStreamin classURLClassLoader
-
getResources
public Enumeration<URL> getResources(String name) throws IOException
Returns only a single instance of the changed resource. There are conflicting requirements for other resources inclusion. This class should "hide" the original resource, hence it should not be included in the resoult. On the other hand, there may be resource with the same name in other JAR which should be included and now is hidden (for example multiple persistence.xml). Maybe a new property to influence this behaviour?- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getClasspath
public String getClasspath()
Support for classpath builder on Tomcat.
-
-