Package org.zeroturnaround.javarebel
Interface Reloader
public interface Reloader
Provides control and notification over/on class loading and reloading.
To use acquire an instance from the ReloaderFactory.
ReloaderFactory.getInstance()
.addClassReloadListener(new ClassEventListener() {
public void onClassEvent(int eventType, Class klass) {
System.out.println(
"Class '" + klass.getName() + "' was reloaded!");
}
});
- Author:
- Jevgeni Kabanov (ekabanov@zeroturnaround.com)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidaddBeforeReloadCheck(Runnable beforeReloadCheck) Register aRunnableto receive notifications before we start reloading all the changed classes.voidaddClassLoadListener(ClassEventListener listener) Register aClassEventListenerto receive notifications when managed classes are loaded.voidaddClassReloadListener(Class<?>[] classes, ClassEventListener listener) Register aClassEventListenerto receive notifications when one of the given managed classes is reloaded.voidaddClassReloadListener(Class<?> klass, ClassEventListener listener) Register aClassEventListenerto receive notifications when the given managed class is reloaded.voidaddClassReloadListener(Reference<? extends ClassEventListener> listener) Register aClassEventListenerto receive notifications when managed classes are reloaded.voidaddClassReloadListener(ClassEventListener listener) Register aClassEventListenerto receive notifications when managed classes are reloaded.voidaddDependencyReloadListener(Class<?> klass, Class<?>[] dependencies, ClassEventListener listener) Register aClassEventListenerto receive notifications when one of the given managed dependent classes is reloaded.voidaddHierarchyReloadListener(Class<?> klass, ClassEventListener listener) Register aClassEventListenerto receive notifications when the given managed class, it's super class or any of it's interfaces is reloaded.voidblockReloadListeners(int priority) Block reloads with priority lower than given from executing before current reload listener has completed.booleancheckAndReload(Class<?> klass) Causes a class to be reloaded if (and only if) the underlying ".class" file has been updated.voidEnsure that classes are checked for changes even when previous check was just performed.booleanhasPendingReload(Class<?> klass) booleanisReloadableClass(Class<?> klass) Returns whether this particular class is managed by JRebel and will be reloaded when it's updated.booleanReturns whether reloading is enabled generally.booleanisReloadingClass(Class<?> klass) Returns whether this particular class is currently being reloaded.voidreinitClass(Class<?> klass) voidreinitOnReload(Class<?> klass) voidreinitOnReload(String className) default voidremoveBeforeReloadCheck(Runnable beforeReloadCheck) Deregister aRunnablefrom receive notifications before we start reloading all the changed classes.voidremoveClassLoadListener(ClassEventListener listener) Deregister aClassEventListener.voidremoveClassReloadListener(Reference<? extends ClassEventListener> listener) Deregister aClassEventListener.voidremoveClassReloadListener(ClassEventListener listener) Deregister aClassEventListener.voidNotify that some class has been reloaded or that it will be reloaded.voidIn case change detection is performed in a background thread wait for change detection and reload to complete.
-
Method Details
-
isReloadEnabled
boolean isReloadEnabled()Returns whether reloading is enabled generally.- Returns:
- Whether reloading is enabled generally.
-
isReloadableClass
Returns whether this particular class is managed by JRebel and will be reloaded when it's updated.- Parameters:
klass- Any class.- Returns:
- Whether this particular class is managed by JRebel and will be reloaded when it's updated.
-
isReloadingClass
Returns whether this particular class is currently being reloaded. This istruewhile theClassEventListener-s receive the events.- Parameters:
klass- Class managed by JRebel.- Returns:
- whether this particular class is currently being reloaded.
- Since:
- 3.0
-
checkAndReload
Causes a class to be reloaded if (and only if) the underlying ".class" file has been updated. Returns true if reloaded, false otherwise.
Note, that as JRebel is lazy, such checks may be necessary if you want to be sure that your metadata is up-to-date. The
ClassEventListenerwill only fire after JRebel has reloaded the class, which by default occurs on method calls to the class in question (and some reflection methods).- Parameters:
klass- The class to check.- Returns:
- true if reloaded, false otherwise.
- See Also:
-
forceCheck
void forceCheck()Ensure that classes are checked for changes even when previous check was just performed. This method should be used with classes that are generated by application server or some framework to make sure they get reloaded immediately, otherwise if a reload check has been just done next check may be delayed. -
triggerClassReload
void triggerClassReload()Notify that some class has been reloaded or that it will be reloaded. -
waitForReload
void waitForReload()In case change detection is performed in a background thread wait for change detection and reload to complete. -
addClassLoadListener
Register aClassEventListenerto receive notifications when managed classes are loaded.- Parameters:
listener- a listener to add
-
removeClassLoadListener
Deregister aClassEventListener.- Parameters:
listener- a listener to remove
-
addClassReloadListener
Register aClassEventListenerto receive notifications when managed classes are reloaded.- Parameters:
listener- a listener to add
-
addClassReloadListener
Register aClassEventListenerto receive notifications when managed classes are reloaded. This method accepts Weak/Soft references.- Parameters:
listener- a reference to the listener
-
addClassReloadListener
Register aClassEventListenerto receive notifications when the given managed class is reloaded.- Parameters:
klass- the class to be associated with the listenerlistener- a listener to add
-
addClassReloadListener
Register aClassEventListenerto receive notifications when one of the given managed classes is reloaded.- Parameters:
classes- the classes to be associated with the listenerlistener- a listener to add
-
addDependencyReloadListener
void addDependencyReloadListener(Class<?> klass, Class<?>[] dependencies, ClassEventListener listener) Register aClassEventListenerto receive notifications when one of the given managed dependent classes is reloaded. When the given class is being checked the dependencies are automatically checked, The registered listener will be provided with the registered class (not a dependency just reloaded).- Parameters:
klass- the class to be associated with the listenerdependencies- the classes that trigger the eventlistener- a listener to add
-
addHierarchyReloadListener
Register aClassEventListenerto receive notifications when the given managed class, it's super class or any of it's interfaces is reloaded. When the given class is being checked the dependencies are automatically checked, The registered listener will be provided with the registered class (not a dependency just reloaded).- Parameters:
klass- the class to be associated with the listenerlistener- a listener to add
-
addBeforeReloadCheck
Register aRunnableto receive notifications before we start reloading all the changed classes. Sometimes we need to re-create some state before class reloads, because some classes need to be transformed at load time based on the state- Parameters:
beforeReloadCheck- the Runnable to run before any reloads- Since:
- 2018.2.3
-
removeBeforeReloadCheck
Deregister aRunnablefrom receive notifications before we start reloading all the changed classes.- Parameters:
beforeReloadCheck- the Runnable to run before any reloads- Since:
- 2023.4.1
-
hasPendingReload
- Parameters:
klass- the class to check- Returns:
- true if the current class is on the reload event queue, e.g. has been reloaded in the last batc
- Since:
- 2020.2.1
-
removeClassReloadListener
Deregister aClassEventListener.- Parameters:
listener- a listener to remove
-
removeClassReloadListener
Deregister aClassEventListener. This method accepts Weak/Soft references.- Parameters:
listener- a listener reference to remove
-
reinitClass
-
reinitOnReload
-
reinitOnReload
-
blockReloadListeners
void blockReloadListeners(int priority) Block reloads with priority lower than given from executing before current reload listener has completed.- Parameters:
priority- the priority
-