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:
    ReloaderFactory, Integration, Configuration, Logger, Plugin
    • Method Detail

      • 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:
        ClassEventListener
      • 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.
      • addClassReloadListener

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

        void addClassReloadListener​(Class<?>[] classes,
                                    ClassEventListener listener)
        Register a ClassEventListener to receive notifications when one of the given managed classes is reloaded.
      • 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).
      • 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).
      • addBeforeReloadCheck

        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
        Since:
        18.2.3
      • 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 -