Enum ClassReloadingStrategy.Strategy

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      REDEFINITION
      Redefines a class using Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition...).
      RETRANSFORMATION
      Redefines a class using Instrumentation.retransformClasses(Class[]).
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[] NO_REDEFINITION
      Indicates that a class is not redefined.
      private static boolean REDEFINE_CLASSES
      Instructs a ClassFileTransformer to redefine classes.
      private boolean redefinition
      true if the REDEFINITION strategy is used.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Strategy​(boolean redefinition)
      Creates a new strategy.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void apply​(java.lang.instrument.Instrumentation instrumentation, java.util.Map<java.lang.Class<?>,​java.lang.instrument.ClassDefinition> classDefinitions)
      Applies this strategy for the given arguments.
      boolean isRedefinition()
      Returns true if this strategy represents REDEFINITION.
      abstract void reset​(java.lang.instrument.Instrumentation instrumentation, ClassFileLocator classFileLocator, java.util.List<java.lang.Class<?>> types)
      Resets the provided types to their original format.
      protected abstract ClassReloadingStrategy.Strategy validate​(java.lang.instrument.Instrumentation instrumentation)
      Validates that this strategy supports a given transformation type.
      static ClassReloadingStrategy.Strategy valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static ClassReloadingStrategy.Strategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • REDEFINITION

        public static final ClassReloadingStrategy.Strategy REDEFINITION

        Redefines a class using Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition...).

        This strategy can be more efficient. However, the redefinition strategy does not allow to reset VM anonymous classes (e.g. classes that represent lambda expressions).

      • RETRANSFORMATION

        public static final ClassReloadingStrategy.Strategy RETRANSFORMATION

        Redefines a class using Instrumentation.retransformClasses(Class[]). This requires synchronization on the ClassReloadingStrategy.instrumentation object.

        This strategy can require more time to be applied but does not struggle to reset VM anonymous classes (e.g. classes that represent lambda expressions).

    • Field Detail

      • NO_REDEFINITION

        private static final byte[] NO_REDEFINITION
        Indicates that a class is not redefined.
      • REDEFINE_CLASSES

        private static final boolean REDEFINE_CLASSES
        Instructs a ClassFileTransformer to redefine classes.
        See Also:
        Constant Field Values
      • redefinition

        private final boolean redefinition
        true if the REDEFINITION strategy is used.
    • Constructor Detail

      • Strategy

        private Strategy​(boolean redefinition)
        Creates a new strategy.
        Parameters:
        redefinition - true if the REDEFINITION strategy is used.
    • Method Detail

      • values

        public static ClassReloadingStrategy.Strategy[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (ClassReloadingStrategy.Strategy c : ClassReloadingStrategy.Strategy.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static ClassReloadingStrategy.Strategy valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • apply

        protected abstract void apply​(java.lang.instrument.Instrumentation instrumentation,
                                      java.util.Map<java.lang.Class<?>,​java.lang.instrument.ClassDefinition> classDefinitions)
                               throws java.lang.instrument.UnmodifiableClassException,
                                      java.lang.ClassNotFoundException
        Applies this strategy for the given arguments.
        Parameters:
        instrumentation - The instrumentation to be used for applying the redefinition.
        classDefinitions - A mapping of the classes to be redefined to their redefinition.
        Throws:
        java.lang.instrument.UnmodifiableClassException - If a class is not modifiable.
        java.lang.ClassNotFoundException - If a class was not found.
      • validate

        protected abstract ClassReloadingStrategy.Strategy validate​(java.lang.instrument.Instrumentation instrumentation)
        Validates that this strategy supports a given transformation type.
        Parameters:
        instrumentation - The instrumentation instance being used.
        Returns:
        This strategy.
      • isRedefinition

        public boolean isRedefinition()
        Returns true if this strategy represents REDEFINITION.
        Returns:
        true if this strategy represents REDEFINITION.
      • reset

        public abstract void reset​(java.lang.instrument.Instrumentation instrumentation,
                                   ClassFileLocator classFileLocator,
                                   java.util.List<java.lang.Class<?>> types)
                            throws java.io.IOException,
                                   java.lang.instrument.UnmodifiableClassException,
                                   java.lang.ClassNotFoundException
        Resets the provided types to their original format.
        Parameters:
        instrumentation - The instrumentation instance to use for class redefinition or retransformation.
        classFileLocator - The class file locator to use.
        types - The types to reset.
        Throws:
        java.io.IOException - If an I/O exception occurs.
        java.lang.instrument.UnmodifiableClassException - If a class is not modifiable.
        java.lang.ClassNotFoundException - If a class could not be found.