Package net.bytebuddy.dynamic.loading
Enum ClassReloadingStrategy.Strategy
- java.lang.Object
-
- java.lang.Enum<ClassReloadingStrategy.Strategy>
-
- net.bytebuddy.dynamic.loading.ClassReloadingStrategy.Strategy
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<ClassReloadingStrategy.Strategy>
- Enclosing class:
- ClassReloadingStrategy
public static enum ClassReloadingStrategy.Strategy extends java.lang.Enum<ClassReloadingStrategy.Strategy>
A strategy which performs the actual redefinition of aClass
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
ClassReloadingStrategy.Strategy.ClassRedefinitionTransformer
A class file transformer that applies a givenClassDefinition
.protected static class
ClassReloadingStrategy.Strategy.ClassResettingTransformer
A transformer that indicates that a class file should not be transformed.
-
Enum Constant Summary
Enum Constants Enum Constant Description REDEFINITION
Redefines a class usingInstrumentation.redefineClasses(java.lang.instrument.ClassDefinition...)
.RETRANSFORMATION
Redefines a class usingInstrumentation.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 aClassFileTransformer
to redefine classes.private boolean
redefinition
true
if theREDEFINITION
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()
Returnstrue
if this strategy representsREDEFINITION
.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.
-
-
-
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 theClassReloadingStrategy.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 aClassFileTransformer
to redefine classes.- See Also:
- Constant Field Values
-
redefinition
private final boolean redefinition
true
if theREDEFINITION
strategy is used.
-
-
Constructor Detail
-
Strategy
private Strategy(boolean redefinition)
Creates a new strategy.- Parameters:
redefinition
-true
if theREDEFINITION
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 namejava.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()
Returnstrue
if this strategy representsREDEFINITION
.- Returns:
true
if this strategy representsREDEFINITION
.
-
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.
-
-