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 Details

    • isReloadEnabled

      boolean isReloadEnabled()
      Returns whether reloading is enabled generally.
      Returns:
      Whether reloading is enabled generally.
    • isReloadableClass

      boolean isReloadableClass(Class<?> klass)
      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

      boolean isReloadingClass(Class<?> klass)
      Returns whether this particular class is currently being reloaded. This is true while the ClassEventListener-s receive the events.
      Parameters:
      klass - Class managed by JRebel.
      Returns:
      whether this particular class is currently being reloaded.
      Since:
      3.0
    • checkAndReload

      boolean checkAndReload(Class<?> klass)

      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 ClassEventListener will 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

      void addClassLoadListener(ClassEventListener listener)
      Register a ClassEventListener to receive notifications when managed classes are loaded.
      Parameters:
      listener - a listener to add
    • removeClassLoadListener

      void removeClassLoadListener(ClassEventListener listener)
      Deregister a ClassEventListener.
      Parameters:
      listener - a listener to remove
    • addClassReloadListener

      void addClassReloadListener(ClassEventListener listener)
      Register a ClassEventListener to receive notifications when managed classes are reloaded.
      Parameters:
      listener - a listener to add
    • addClassReloadListener

      void addClassReloadListener(Reference<? extends ClassEventListener> listener)
      Register a ClassEventListener to receive notifications when managed classes are reloaded. This method accepts Weak/Soft references.
      Parameters:
      listener - a reference to the listener
    • addClassReloadListener

      void addClassReloadListener(Class<?> klass, ClassEventListener listener)
      Register a ClassEventListener to receive notifications when the given managed class is reloaded.
      Parameters:
      klass - the class to be associated with the listener
      listener - a listener to add
    • addClassReloadListener

      void addClassReloadListener(Class<?>[] classes, ClassEventListener listener)
      Register a ClassEventListener to receive notifications when one of the given managed classes is reloaded.
      Parameters:
      classes - the classes to be associated with the listener
      listener - a listener to add
    • addDependencyReloadListener

      void addDependencyReloadListener(Class<?> klass, Class<?>[] dependencies, ClassEventListener listener)
      Register a ClassEventListener to 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 listener
      dependencies - the classes that trigger the event
      listener - a listener to add
    • addHierarchyReloadListener

      void addHierarchyReloadListener(Class<?> klass, ClassEventListener listener)
      Register a ClassEventListener to 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 listener
      listener - a listener to add
    • addBeforeReloadCheck

      default void addBeforeReloadCheck(Runnable beforeReloadCheck)
      Register a Runnable to 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

      default void removeBeforeReloadCheck(Runnable beforeReloadCheck)
      Deregister a Runnable from receive notifications before we start reloading all the changed classes.
      Parameters:
      beforeReloadCheck - the Runnable to run before any reloads
      Since:
      2023.4.1
    • hasPendingReload

      boolean hasPendingReload(Class<?> klass)
      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

      void removeClassReloadListener(ClassEventListener listener)
      Deregister a ClassEventListener.
      Parameters:
      listener - a listener to remove
    • removeClassReloadListener

      void removeClassReloadListener(Reference<? extends ClassEventListener> listener)
      Deregister a ClassEventListener. This method accepts Weak/Soft references.
      Parameters:
      listener - a listener reference to remove
    • reinitClass

      void reinitClass(Class<?> klass)
    • reinitOnReload

      void reinitOnReload(Class<?> klass)
    • reinitOnReload

      void reinitOnReload(String className)
    • blockReloadListeners

      void blockReloadListeners(int priority)
      Block reloads with priority lower than given from executing before current reload listener has completed.
      Parameters:
      priority - the priority