Interface Integration
-
public interface IntegrationProvides hooks for integrating JRebel with custom containers, frameworks and classloaders. To use it acquire an instance from
IntegrationFactoryA typical (classloader) integration will look like this:
class MyClassLoader extends URLClassLoader { public MyClassLoader() { ... IntegrationFactory.getInstance().registerClassLoader( this, new FindResourceClassResourceSource(this))); } ... public Class findClass(String classname) { synchronized(classloader) { Class result = classloader.findLoadedClass(classname); if (result != null) return result; result = IntegrationFactory.getInstance() .findReloadableClass(this, classname); if (result != null) return result; } ... } }You can use the
addIntegrationProcessor(String, ClassBytecodeProcessor)andaddIntegrationProcessor(String[], ClassBytecodeProcessor)instrument specific classes to enhance their behaviour with JRebel.You can use
#addManagedPreProcessor(ClassBytecodeProcessor)to register a preprocessor for all classes managed by JRebel e.g. to enable container-specific AOP- Author:
- Jevgeni Kabanov (ekabanov@zeroturnaround.com)
- See Also:
IntegrationFactory,ServletIntegration,Configuration,Reloader,Logger,Plugin
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddAfterMainCallback(AfterMainCallback callback)Registers a callback that will be invoked after the main method is called.voidaddBootClassProcessor(String className, ClassBytecodeProcessor processor)Adds a bytecode processor for the given class in boot classloader.voidaddBootClassProcessor(ClassBytecodeProcessor classBytecodeProcessor)Adds a bytecode processor in boot classloader.voidaddClassLoaderDestructionListener(ClassLoader cl, ClassLoaderDestructionListener listener)Registers a call back invoked when a given class loader is being destroyed.voidaddIntegrationProcessor(ClassLoader cl, String[] classNames, ClassBytecodeProcessor processor)Adds a bytecode processor for the set of given classes in the given classloader.voidaddIntegrationProcessor(ClassLoader cl, String className, ClassBytecodeProcessor processor)Adds a bytecode processor for the given class in the given classloader.voidaddIntegrationProcessor(ClassLoader cl, ClassBytecodeProcessor processor)Adds a bytecode processor for the given classloader.voidaddIntegrationProcessor(ClassLoader cl, ClassBytecodeProcessor processor, boolean managedOnly)AAdds a bytecode processor for the given classloader.voidaddIntegrationProcessor(String[] classNames, ClassBytecodeProcessor processor)Adds a bytecode processor for the set of given classes.voidaddIntegrationProcessor(String className, ClassBytecodeProcessor processor)Adds a bytecode processor for the given class.voidaddIntegrationProcessor(ClassBytecodeProcessor processor, boolean managedOnly)Adds a bytecode processor for all classes.voidbindToClassLoader(ClassLoader cl, Object value)Add reference from given class loader to given object.Class<?>defineReloadableClass(ClassLoader cl, String className, byte[] bytecode, ProtectionDomain protectionDomain)Same as defineReloadableClass(cl, className, bytecode, protectionDomain, true)Class<?>defineReloadableClass(ClassLoader cl, String className, byte[] bytecode, ProtectionDomain protectionDomain, boolean processedByLoader)(Re)defines a class managed by JRebel.Class<?>defineReloadableClass(ClassLoader cl, String className, Resource mutableResource, ProtectionDomain protectionDomain, boolean processedByLoader)(Re)defines a class managed by JRebel.voiddisablePlugins(ClassLoader cl)Disable running plugins in given class loader.voiddisableReloadDetection(ClassLoader cl)Disable class reload check in given class loader.voiddisableReloading(ClassLoader cl)Disable class reloading in given class loader.voiddisableSecurityManager()Disables the SecurityManager in the current thread.voidenableSecurityManager()Re-enables the disabled SecurityManager in the current thread.URLfindRebelResource(ClassLoader cl, String name)Resolves resources only managed by JRebel.Enumeration<URL>findRebelResources(ClassLoader cl, String name)Resolves resources only managed by JRebel.Class<?>findReloadableClass(ClassLoader cl, String className)Resolves classes managed by JRebel.URLfindResource(ClassLoader cl, String name)Resolves resources managed by JRebel.Enumeration<URL>findResources(ClassLoader cl, String name)Resolves resources managed by JRebel.ClassBytecodeProcessorCachegetClassBytecodeProcessorCache()Returns an instance ofClassBytecodeProcessorCachewhich can be used by class bytecode processors to cache their transformations between runs.RebelSource[]getRebelSources(ClassLoader cl)Returns the additional class path of the givenClassLoadermanaged by JRebel.URL[]getRebelURLs(ClassLoader cl)Returns the additional class path of the givenClassLoadermanaged by JRebel.URL[]getRebelURLs(ClassLoader cl, boolean onlyFullMatch)Returns the additional class path of the givenClassLoadermanaged by JRebel.ScanHelpergetScanHelper(ClassLoader cl, String name)Returns helper object to perform class path scanning in the givenClassLoader.URLgetTransparentResource(ClassLoader cl, String name)Returns the original resource with given name.Enumeration<URL>getTransparentResources(ClassLoader cl, String name)Returns the original resources with given name.booleanisCheckingPluginDependencies(ClassLoader cl)ReturnstrueifPlugin.checkDependencies(ClassLoader, ClassResourceSource)is being called for the given class loader.booleanisFilteringMissingMethods()Returnstrueif we are filtering out parent class methods for OSGI, that the class itself can not see.booleanisRegisteredClassLoader(ClassLoader cl)Says if thisClassLoaderis registerd with JRebel.booleanisResourceReplaced(ClassLoader cl, String name)Returnstrueif the given resource is managed by JRebel.voidrecordClassResource(ClassLoader cl, String className, URL url)Record location of found class.voidredefineClasses(ClassDefinition... classDefinitions)Redefine a set of classes managed by JRebel.booleanredefineReloadableClass(Class<?> klass, byte[] bytecode)Same as redefineReloadableClass(klass, bytecode, true)booleanredefineReloadableClass(Class<?> klass, byte[] bytecode, boolean processedByLoader)Redefines a class managed by JRebel.voidregisterClassLoader(ClassLoader cl, ClassResourceSource cfs)Registers aClassLoaderwith JRebel associating with it the class-to-file resolution strategy provided byClassFileSource.voidregisterModularClassLoader(ClassLoader cl)Enable special handling forClassLoadersystems with non-transitive class loading e.g.voidreinitializeClassLoader(ClassLoader cl)Reinitializes theClassLoaderwith JRebel.voidremoveClassLoaderDestructionListener(ClassLoaderDestructionListener listener)Removes a call back invoked when a given class loader is being destroyed.voidremoveIntegrationProcessor(ClassBytecodeProcessor processor)Remove bytecode processor.voidremoveIntegrationProcessors(ClassLoader cl)Remove bytecode processors that are loaded by the ClassLoadervoidreportError(Throwable e, String version, String jarFile)Report CBP failure, implementation must be async.voidunregisterClassLoader(ClassLoader cl)Unregisters theClassLoaderfrom JRebel.voiduseSeparateCacheForClassesAndResources(ClassLoader cl)Cache results for class and resource request separately.
-
-
-
Method Detail
-
registerClassLoader
void registerClassLoader(ClassLoader cl, ClassResourceSource cfs)
Registers aClassLoaderwith JRebel associating with it the class-to-file resolution strategy provided byClassFileSource. It is necessary to do this before any calls tofindReloadableClass(ClassLoader, String), the best place is usually the constructor.- Parameters:
cl- The custom class loader being integrated.cfs- The class-to-file resolution strategy source.- See Also:
ClassResourceSource
-
reinitializeClassLoader
void reinitializeClassLoader(ClassLoader cl)
Reinitializes theClassLoaderwith JRebel.This should be called if the class path of the given
ClassLoaderwas updated.- Parameters:
cl- The custom class loader being integrated.
-
unregisterClassLoader
void unregisterClassLoader(ClassLoader cl)
Unregisters theClassLoaderfrom JRebel. It is recommended to do this in case the correspondingClassLoaderis destroyed (e.g. the web application is undeployed).- Parameters:
cl- The custom class loader being integrated.
-
isRegisteredClassLoader
boolean isRegisteredClassLoader(ClassLoader cl)
Says if thisClassLoaderis registerd with JRebel.- Parameters:
cl- The custom class loader being integrated.- Returns:
-
registerModularClassLoader
void registerModularClassLoader(ClassLoader cl)
Enable special handling forClassLoadersystems with non-transitive class loading e.g. OSGI, NetBeans. This method does not replaceregisterClassLoader(ClassLoader, ClassResourceSource).- Parameters:
cl- The custom class loader being integrated.
-
getRebelURLs
URL[] getRebelURLs(ClassLoader cl)
Returns the additional class path of the givenClassLoadermanaged by JRebel.Same as
getRebelURLs(cl, false).- Parameters:
cl- The custom class loader being integrated.- Returns:
- additional class path of the given
ClassLoaderornullif nothing found.
-
getRebelURLs
URL[] getRebelURLs(ClassLoader cl, boolean onlyFullMatch)
Returns the additional class path of the givenClassLoadermanaged by JRebel.- Parameters:
cl- The custom class loader being integrated.onlyFullMatch- whether to only return locations with no custom patterns.- Returns:
- additional class path of the given
ClassLoaderornullif nothing found.
-
getRebelSources
RebelSource[] getRebelSources(ClassLoader cl)
Returns the additional class path of the givenClassLoadermanaged by JRebel.- Parameters:
cl- The custom class loader being integrated.- Returns:
- additional class path of the given
ClassLoaderornullif nothing found.
-
getScanHelper
ScanHelper getScanHelper(ClassLoader cl, String name)
Returns helper object to perform class path scanning in the givenClassLoader. NOTE: this api is experimental and may be removed or changed in future versions.- Parameters:
cl- The class loader used to find resources to scan.name- name of resource to start scanning from.- Returns:
- helper for class path scanning or
nullif not available.
-
findReloadableClass
Class<?> findReloadableClass(ClassLoader cl, String className) throws ClassNotFoundException
Resolves classes managed by JRebel. These and only these classes will be reloadable. Returns null if class couldn't be resolved and the non-JRebel class loading should be used as fail-over. ThrowsClassNotFoundExceptionif class does not exist and the non-JRebel class loading should be skipped.- Parameters:
cl- The custom class loader being integrated.classname- The public class name.- Returns:
- Resolved class or null.
- Throws:
ClassNotFoundException- if class does not exist.- See Also:
#defineReloadableClass(ClassLoader, String, byte[])
-
defineReloadableClass
Class<?> defineReloadableClass(ClassLoader cl, String className, Resource mutableResource, ProtectionDomain protectionDomain, boolean processedByLoader)
(Re)defines a class managed by JRebel. When the class is reloaded, the Resource provided here is used to get the new bytes. This can be used to re-generate the bytes for a proxy class after a reload. Returns null if this class loader is not registered with JRebel.- Parameters:
cl- The custom class loader being integrated.className- The public class name.resource- bytes for the class.protectionDomain- The ProtectionDomain of the class (may benull).processedByLoader- Whether given bytes should be processed by class loader in the same way as a normally loaded classes. Set tofalsewhen class is supposed to be define similarly to reflectively callingClassLoader.defineClassthat bypasses logic inside defining loader.- Returns:
- (Re)defined class or
null. - Since:
- 18.2.5
-
defineReloadableClass
Class<?> defineReloadableClass(ClassLoader cl, String className, byte[] bytecode, ProtectionDomain protectionDomain, boolean processedByLoader)
(Re)defines a class managed by JRebel.This method may be called for loading as well as reloading the class.
This method is intended to replace defineClass, e.g. used from the same context as defineClass is currently used. So in normal java ClassLoader the caller of defineClass should already be synchronized and we should not do it inside defineReloadableClass in order to avoid creating extra deadlocks.
The defined class will only be reloaded if this method is called again. Even if the class was first loaded by
Returns null if this class loader is not registered with JRebel.findReloadableClass(ClassLoader, String)the resolved class resource will not be checked for updates.- Parameters:
cl- The custom class loader being integrated.className- The public class name.bytecode- class bytes.protectionDomain- The ProtectionDomain of the class (may benull).processedByLoader- Whether given bytes should be processed by class loader in the same way as a normally loaded classes. Set tofalsewhen class is supposed to be define similarly to reflectively callingClassLoader.defineClassthat bypasses logic inside defining loader.- Returns:
- (Re)defined class or
null. - Since:
- 7.0.1
-
defineReloadableClass
Class<?> defineReloadableClass(ClassLoader cl, String className, byte[] bytecode, ProtectionDomain protectionDomain)
Same as defineReloadableClass(cl, className, bytecode, protectionDomain, true)- Since:
- 3.0
-
redefineReloadableClass
boolean redefineReloadableClass(Class<?> klass, byte[] bytecode, boolean processedByLoader)
Redefines a class managed by JRebel.- Parameters:
klass- Class managed by JRebel.bytecode- class bytes.processedByLoader- Whether given bytes should be processed by class loader in the same way as a normally loaded classes. Set tofalsewhen class is supposed to be define similarly to reflectively callingClassLoader.defineClassthat bypasses logic inside defining loader.- Returns:
trueif the class was managed by JRebel and redefined.- Since:
- 7.0.1
-
redefineReloadableClass
boolean redefineReloadableClass(Class<?> klass, byte[] bytecode)
Same as redefineReloadableClass(klass, bytecode, true)- Since:
- 3.0
-
redefineClasses
void redefineClasses(ClassDefinition... classDefinitions)
Redefine a set of classes managed by JRebel.- Parameters:
classDefinitions- Array of ClassDefinition objects containing the Class and new class-bytes
-
isResourceReplaced
boolean isResourceReplaced(ClassLoader cl, String name)
Returnstrueif the given resource is managed by JRebel.In that case resources can be resolved using the corresponding methods of the
Integration. If any of these methods returns anullit must be returned by theClassLoaderas well.- Parameters:
cl- The custom class loader being integrated.name- The public resource name.- Returns:
trueif the given resource is managed by JRebel.
-
findResource
URL findResource(ClassLoader cl, String name)
Resolves resources managed by JRebel.- Parameters:
cl- The custom class loader being integrated.name- The public resource name.- Returns:
- Resolved resource URL or null.
-
findRebelResource
URL findRebelResource(ClassLoader cl, String name)
Resolves resources only managed by JRebel.- Parameters:
cl- The custom class loader being integrated.name- The public resource name.- Returns:
- Resolved resource URL or null.
-
findResources
Enumeration<URL> findResources(ClassLoader cl, String name)
Resolves resources managed by JRebel.- Parameters:
cl- The custom class loader being integrated.name- The public resource name.- Returns:
- Resolved resource URLs or null.
-
findRebelResources
Enumeration<URL> findRebelResources(ClassLoader cl, String name)
Resolves resources only managed by JRebel.- Parameters:
cl- The custom class loader being integrated.name- The public resource name.- Returns:
- Resolved resource URLs or null.
-
getTransparentResources
Enumeration<URL> getTransparentResources(ClassLoader cl, String name)
Returns the original resources with given name. This is used to get the original result unaltered by JRebel.- Parameters:
cl- The custom class loader being integrated.name- The resource name.- Returns:
- Resolved resource URLs or null.
-
getTransparentResource
URL getTransparentResource(ClassLoader cl, String name)
Returns the original resource with given name. This is used to get the original result unaltered by JRebel.- Parameters:
cl- The custom class loader being integrated.name- The resource name.- Returns:
- Resolved resource URL or null.
-
recordClassResource
void recordClassResource(ClassLoader cl, String className, URL url)
Record location of found class. This method may be used to improve cache hit ration for overhead resource requests in class loaders whose findClass does not call findResource.- Parameters:
cl- The custom class loader being integrated.name- The public class name.url- URL of class resource.- Since:
- 4.6
-
useSeparateCacheForClassesAndResources
void useSeparateCacheForClassesAndResources(ClassLoader cl)
Cache results for class and resource request separately. Use when the result of resource lookup as returned by findResource may be different from what is recorded with recordClassResource.- Parameters:
cl- The custom class loader being integrated.
-
addIntegrationProcessor
void addIntegrationProcessor(ClassLoader cl, String className, ClassBytecodeProcessor processor)
Adds a bytecode processor for the given class in the given classloader. It will be run before that class is loaded and is mainly use to enable integration with a specific framework or classloader. Allows to additionally restrict the bytecode processing to the given classloader.
-
addIntegrationProcessor
void addIntegrationProcessor(String className, ClassBytecodeProcessor processor)
Adds a bytecode processor for the given class. It will be run before that class is loaded and is mainly use to enable integration with a specific framework or classloader.
-
addIntegrationProcessor
void addIntegrationProcessor(ClassLoader cl, ClassBytecodeProcessor processor)
Adds a bytecode processor for the given classloader. It will be run before that class is loaded and is mainly use to enable integration with a specific framework or classloader. Allows to additionally restrict the bytecode processing to the given classloader.
-
addIntegrationProcessor
void addIntegrationProcessor(ClassBytecodeProcessor processor, boolean managedOnly)
Adds a bytecode processor for all classes. It will be run before that class is loaded and is mainly used for integration with preprocessors like AspectJ.If
managedOnlyistruethe processor will only be run for the classes managed by JRebel. This is useful to enable processing usually done in the class loaderfindClass()method, e.g. the JBoss AOP.
-
addIntegrationProcessor
void addIntegrationProcessor(ClassLoader cl, ClassBytecodeProcessor processor, boolean managedOnly)
AAdds a bytecode processor for the given classloader. It will be run before that class is loaded and is mainly used for integration with preprocessors like AspectJ.If
managedOnlyistruethe processor will only be run for the classes managed by JRebel. This is useful to enable processing usually done in the class loaderfindClass()method, e.g. the JBoss AOP.
-
addIntegrationProcessor
void addIntegrationProcessor(String[] classNames, ClassBytecodeProcessor processor)
Adds a bytecode processor for the set of given classes. It will be run before those classes are loaded and is mainly use to enable integration with a specific framework or classloader.
-
addIntegrationProcessor
void addIntegrationProcessor(ClassLoader cl, String[] classNames, ClassBytecodeProcessor processor)
Adds a bytecode processor for the set of given classes in the given classloader. It will be run before those classes are loaded and is mainly use to enable integration with a specific framework or classloader. Allows to additionally restrict the bytecode processing to the given classloader.
-
removeIntegrationProcessor
void removeIntegrationProcessor(ClassBytecodeProcessor processor)
Remove bytecode processor.
-
removeIntegrationProcessors
void removeIntegrationProcessors(ClassLoader cl)
Remove bytecode processors that are loaded by the ClassLoader
-
addBootClassProcessor
void addBootClassProcessor(String className, ClassBytecodeProcessor processor)
Adds a bytecode processor for the given class in boot classloader. It will be run before that class is loaded and is mainly use to enable integration with a specific framework or classloader. This API is only available when JRebel is configured as java agent.
-
addBootClassProcessor
void addBootClassProcessor(ClassBytecodeProcessor classBytecodeProcessor)
Adds a bytecode processor in boot classloader. It is mainly use to enable integration with a specific framework or classloader. This API is only available when JRebel is configured as java agent.
-
reportError
void reportError(Throwable e, String version, String jarFile)
Report CBP failure, implementation must be async.- Parameters:
e-version-jarFile-
-
addClassLoaderDestructionListener
void addClassLoaderDestructionListener(ClassLoader cl, ClassLoaderDestructionListener listener)
Registers a call back invoked when a given class loader is being destroyed.- Parameters:
cl- The custom class loader being integrated.listener- class loader destruction listener.
-
removeClassLoaderDestructionListener
void removeClassLoaderDestructionListener(ClassLoaderDestructionListener listener)
Removes a call back invoked when a given class loader is being destroyed.- Parameters:
listener- class loader destruction listener.
-
isCheckingPluginDependencies
boolean isCheckingPluginDependencies(ClassLoader cl)
ReturnstrueifPlugin.checkDependencies(ClassLoader, ClassResourceSource)is being called for the given class loader.During the given process no class path entries should be altered.
-
isFilteringMissingMethods
boolean isFilteringMissingMethods()
Returnstrueif we are filtering out parent class methods for OSGI, that the class itself can not see. Used to disable class resource finding in a classloader if it can find the class as Resource but can not load that class.
-
disablePlugins
void disablePlugins(ClassLoader cl)
Disable running plugins in given class loader.
-
disableReloading
void disableReloading(ClassLoader cl)
Disable class reloading in given class loader. Resource management will still be enabled.
-
disableReloadDetection
void disableReloadDetection(ClassLoader cl)
Disable class reload check in given class loader. Resource management will still be enabled.
-
addAfterMainCallback
void addAfterMainCallback(AfterMainCallback callback)
Registers a callback that will be invoked after the main method is called. Callback will be invoked in the same order as they were added. If a callback is added after the main method has been called it will be invoked immediately.
-
disableSecurityManager
void disableSecurityManager()
Disables the SecurityManager in the current thread.
-
enableSecurityManager
void enableSecurityManager()
Re-enables the disabled SecurityManager in the current thread.
-
getClassBytecodeProcessorCache
ClassBytecodeProcessorCache getClassBytecodeProcessorCache()
Returns an instance ofClassBytecodeProcessorCachewhich can be used by class bytecode processors to cache their transformations between runs.
-
bindToClassLoader
void bindToClassLoader(ClassLoader cl, Object value)
Add reference from given class loader to given object. This will prevent GC from collecting the input object before class loader is collected.- Parameters:
cl- Class loader that will be used to keep object alive.value- Object that will be made to live as long as class loader.- Since:
- 2019.2.2
-
-