Class HotswapTransformer

  • All Implemented Interfaces:
    ClassFileTransformer

    public class HotswapTransformer
    extends Object
    implements ClassFileTransformer
    Java instrumentation transformer.

    The is the single instance of transformer registered by HotswapAgent. It will delegate to plugins to do the transformer work.

    Author:
    Jiri Bubnik
    • Field Detail

      • redefinitionTransformers

        protected Map<String,​org.hotswap.agent.util.HotswapTransformer.RegisteredTransformersRecord> redefinitionTransformers
      • otherTransformers

        protected Map<String,​org.hotswap.agent.util.HotswapTransformer.RegisteredTransformersRecord> otherTransformers
    • Constructor Detail

      • HotswapTransformer

        public HotswapTransformer()
    • Method Detail

      • getIncludedClassLoaderPatterns

        public List<Pattern> getIncludedClassLoaderPatterns()
      • setIncludedClassLoaderPatterns

        public void setIncludedClassLoaderPatterns​(List<Pattern> includedClassLoaderPatterns)
      • setExcludedClassLoaderPatterns

        public void setExcludedClassLoaderPatterns​(List<Pattern> excludedClassLoaderPatterns)
        Parameters:
        excludedClassLoaderPatterns - the excludedClassLoaderPatterns to set
      • getExcludedClassLoaderPatterns

        public List<Pattern> getExcludedClassLoaderPatterns()
      • registerTransformer

        public void registerTransformer​(ClassLoader classLoader,
                                        String classNameRegexp,
                                        HaClassFileTransformer transformer)
        Register a transformer for a regexp matching class names. Used by OnClassLoadEvent annotation respective OnClassLoadedHandler.
        Parameters:
        classLoader - the classloader to which this transformation is associated
        classNameRegexp - regexp to match fully qualified class name. Because "." is any character in regexp, this will match / in the transform method as well (diffentence between java/lang/String and java.lang.String).
        transformer - the transformer to be called for each class matching regexp.
      • removeTransformer

        public void removeTransformer​(String classNameRegexp,
                                      HaClassFileTransformer transformer)
        Remove registered transformer.
        Parameters:
        classNameRegexp - regexp to match fully qualified class name.
        transformer - currently registered transformer
      • closeClassLoader

        public void closeClassLoader​(ClassLoader classLoader)
        Remove all transformers registered with a classloader
        Parameters:
        classLoader -
      • ensureClassLoaderInitialized

        protected boolean ensureClassLoaderInitialized​(ClassLoader classLoader,
                                                       ProtectionDomain protectionDomain)
        Every classloader should be initialized. Usually if anything interesting happens, it is initialized during plugin initialization process. However, some plugins (e.g. Hotswapper) are triggered during classloader initialization process itself (@Init on static method). In this case, the plugin will be never invoked, until the classloader initialization is invoked from here. Schedule with some timeout to allow standard plugin initialization process to precede.
        Parameters:
        classLoader - the classloader to which this transformation is associated
        protectionDomain - associated protection domain (if any)
      • normalizeTypeRegexp

        protected String normalizeTypeRegexp​(String registeredType)
        Transform type to ^regexp$ form - match only whole pattern.
        Parameters:
        registeredType - type
        Returns: