Annotation Type OnClassLoadEvent


  • @Target(METHOD)
    @Retention(RUNTIME)
    @Documented
    public @interface OnClassLoadEvent
    Define plugin callback method on class load by classloader (application class is loaded or reloaded by hotswap).

    Method attribute types:

    • byte[] - the input byte buffer in class file format - must not be modified
    • ClassLoader - the defining loader of the class to be transformed, may be null if the bootstrap loader
    • String - classname - the name of the class in the internal form of fully qualified class and interface names. For example, "java/util/List".
    • Class - classBeingRedefined - if this is triggered by a redefine or retransform, the class being redefined or retransformed; if this is a class load, null
    • ProtectionDomain - the protection domain of the class being defined or redefined
    • ClassPool - javassist default ClassPool
    • CtClass - javassist class created from byte[] source. If the method returns null/void, this class is used as transformation result. You can modify this class directly.
    • AppClassLoaderExecutor - executor to run code in app classloader
    • LoadEvent - originating load event. If classBeingRedefined is null, this is DEFINE, otherwise REDEFINE.

    If registered on static method, transformation is invoked even before the plugin is initialized. You need at least one static transformation method for a plugin to trigger plugin initialization.

    This event is triggered only AFTER the class is loaded by a classloader. Many frameworks like Spring or Hibernate use custom classpath scanning to discover annotated classes. In this case a change cannot be triggered only by @OnClassLoadEvent method (the class is never loaded) and you need to cover this case using @OnClassFileEvent handler. See HibernatePlugin#newEntity() method annotated with OnClassFileEvent for an example.

    Author:
    Jiri Bubnik
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      String classNameRegexp
      Regexp of class name.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      LoadEvent[] events
      Specify list of events to watch for (class is loaded by the ClassLoader / redefined by hotswap mechanism).
      boolean skipAnonymous
      Anonymous classes (e.g.
      boolean skipSynthetic
      Classes created at runtime are usually skipped
    • Element Detail

      • classNameRegexp

        String classNameRegexp
        Regexp of class name.
      • events

        LoadEvent[] events
        Specify list of events to watch for (class is loaded by the ClassLoader / redefined by hotswap mechanism). By default are both DEFINE and REDEFINE events enabled.
        Returns:
        list of class load events
        Default:
        {org.hotswap.agent.annotation.LoadEvent.DEFINE, org.hotswap.agent.annotation.LoadEvent.REDEFINE}
      • skipAnonymous

        boolean skipAnonymous
        Anonymous classes (e.g. MyClass$1, MyClass$2, ...) are usually reloaded with main class MyClass, but the transformation should be done only on the main class.
        Returns:
        false to include anonymous classes.
        Default:
        true
      • skipSynthetic

        boolean skipSynthetic
        Classes created at runtime are usually skipped
        Returns:
        false to include synthetic classes.
        Default:
        true