public static enum ClassReloadingStrategy.Strategy extends java.lang.Enum<ClassReloadingStrategy.Strategy>
Class
.Modifier and Type | Class and Description |
---|---|
protected static class |
ClassReloadingStrategy.Strategy.ClassRedefinitionTransformer
A class file transformer that applies a given
ClassDefinition . |
protected static class |
ClassReloadingStrategy.Strategy.ClassResettingTransformer
A transformer that indicates that a class file should not be transformed.
|
Enum Constant and Description |
---|
REDEFINITION
Redefines a class using
Instrumentation.redefineClasses(java.lang.instrument.ClassDefinition...) . |
RETRANSFORMATION
Redefines a class using
Instrumentation.retransformClasses(Class[]) . |
Modifier and Type | Field and 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. |
Modifier and Type | Method and 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.
|
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).
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).
private static final byte[] NO_REDEFINITION
private static final boolean REDEFINE_CLASSES
ClassFileTransformer
to redefine classes.private final boolean redefinition
true
if the REDEFINITION
strategy
is used.public static ClassReloadingStrategy.Strategy[] values()
for (ClassReloadingStrategy.Strategy c : ClassReloadingStrategy.Strategy.values()) System.out.println(c);
public static ClassReloadingStrategy.Strategy valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is nullprotected 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
instrumentation
- The instrumentation to be used for applying the redefinition.classDefinitions
- A mapping of the classes to be redefined to their redefinition.java.lang.instrument.UnmodifiableClassException
- If a class is not modifiable.java.lang.ClassNotFoundException
- If a class was not found.protected abstract ClassReloadingStrategy.Strategy validate(java.lang.instrument.Instrumentation instrumentation)
instrumentation
- The instrumentation instance being used.public boolean isRedefinition()
true
if this strategy represents REDEFINITION
.true
if this strategy represents REDEFINITION
.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
instrumentation
- The instrumentation instance to use for class redefinition or retransformation.classFileLocator
- The class file locator to use.types
- The types to reset.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.