Enum AgentBuilder.RedefinitionStrategy
- java.lang.Object
-
- java.lang.Enum<AgentBuilder.RedefinitionStrategy>
-
- net.bytebuddy.agent.builder.AgentBuilder.RedefinitionStrategy
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<AgentBuilder.RedefinitionStrategy>
- Enclosing interface:
- AgentBuilder
public static enum AgentBuilder.RedefinitionStrategy extends java.lang.Enum<AgentBuilder.RedefinitionStrategy>
A redefinition strategy regulates how already loaded classes are modified by a built agent.
Important: Most JVMs do not support changes of a class's structure after a class was already loaded. Therefore, it is typically required that this class file transformer was built while enabling
AgentBuilder.disableClassFormatChanges()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AgentBuilder.RedefinitionStrategy.BatchAllocator
A batch allocator which is responsible for applying a redefinition in a batches.protected static class
AgentBuilder.RedefinitionStrategy.Collector
A collector is responsible for collecting classes that are to be considered for modification.static interface
AgentBuilder.RedefinitionStrategy.DiscoveryStrategy
A strategy for discovering types to redefine.protected static interface
AgentBuilder.RedefinitionStrategy.Dispatcher
A dispatcher for interacting with the instrumentation API.static interface
AgentBuilder.RedefinitionStrategy.Listener
A listener to be applied during a redefinition.static interface
AgentBuilder.RedefinitionStrategy.ResubmissionScheduler
A resubmission scheduler is responsible for scheduling a job that is resubmitting unloaded types that failed during retransformation.protected static interface
AgentBuilder.RedefinitionStrategy.ResubmissionStrategy
A resubmission strategy is responsible for enabling resubmission of types that failed to resubmit.
-
Enum Constant Summary
Enum Constants Enum Constant Description DISABLED
Disables redefinition such that already loaded classes are not affected by the agent.REDEFINITION
Applies a redefinition to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded.RETRANSFORMATION
Applies a retransformation to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded.
-
Field Summary
Fields Modifier and Type Field Description protected static AgentBuilder.RedefinitionStrategy.Dispatcher
DISPATCHER
A dispatcher to use for interacting with the instrumentation API.private boolean
enabled
Indicates that this redefinition strategy is enabled.private boolean
retransforming
true
if this strategy applies retransformation.
-
Constructor Summary
Constructors Modifier Constructor Description private
RedefinitionStrategy(boolean enabled, boolean retransforming)
Creates a new redefinition strategy.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
apply(java.lang.instrument.Instrumentation instrumentation, AgentBuilder.Listener listener, AgentBuilder.CircularityLock circularityLock, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.LocationStrategy locationStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.RawMatcher matcher)
Applies this redefinition strategy by submitting all loaded types to redefinition.protected abstract void
check(java.lang.instrument.Instrumentation instrumentation)
Checks if this strategy can be applied to the supplied instrumentation instance.protected boolean
isEnabled()
Indicates that this redefinition strategy applies a modification of already loaded classes.protected boolean
isRetransforming()
Indicates if this strategy requires a class file transformer to be registered with a hint to apply the transformer for retransformation.protected abstract AgentBuilder.RedefinitionStrategy.Collector
make()
Creates a collector instance that is responsible for collecting loaded classes for potential retransformation.static AgentBuilder.RedefinitionStrategy
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static AgentBuilder.RedefinitionStrategy[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
DISABLED
public static final AgentBuilder.RedefinitionStrategy DISABLED
Disables redefinition such that already loaded classes are not affected by the agent.
-
REDEFINITION
public static final AgentBuilder.RedefinitionStrategy REDEFINITION
Applies a redefinition to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded. The created
ClassFileTransformer
is not registered for applying retransformations.Using this strategy, a redefinition is applied as a single transformation request. This means that a single illegal redefinition of a class causes the entire redefinition attempt to fail.
Note: When applying a redefinition, it is normally required to use a
AgentBuilder.TypeStrategy
that applies a redefinition instead of rebasing classes such asAgentBuilder.TypeStrategy.Default.REDEFINE
. Also, consider the constrains given by this type strategy.
-
RETRANSFORMATION
public static final AgentBuilder.RedefinitionStrategy RETRANSFORMATION
Applies a retransformation to all classes that are already loaded and that would have been transformed if the built agent was registered before they were loaded. The created
ClassFileTransformer
is registered for applying retransformations.Using this strategy, a retransformation is applied as a single transformation request. This means that a single illegal retransformation of a class causes the entire retransformation attempt to fail.
Note: When applying a retransformation, it is normally required to use a
AgentBuilder.TypeStrategy
that applies a redefinition instead of rebasing classes such asAgentBuilder.TypeStrategy.Default.REDEFINE
. Also, consider the constrains given by this type strategy.
-
-
Field Detail
-
DISPATCHER
protected static final AgentBuilder.RedefinitionStrategy.Dispatcher DISPATCHER
A dispatcher to use for interacting with the instrumentation API.
-
enabled
private final boolean enabled
Indicates that this redefinition strategy is enabled.
-
retransforming
private final boolean retransforming
true
if this strategy applies retransformation.
-
-
Method Detail
-
values
public static AgentBuilder.RedefinitionStrategy[] 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 (AgentBuilder.RedefinitionStrategy c : AgentBuilder.RedefinitionStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static AgentBuilder.RedefinitionStrategy 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
-
isRetransforming
protected boolean isRetransforming()
Indicates if this strategy requires a class file transformer to be registered with a hint to apply the transformer for retransformation.- Returns:
true
if a class file transformer must be registered with a hint for retransformation.
-
check
protected abstract void check(java.lang.instrument.Instrumentation instrumentation)
Checks if this strategy can be applied to the supplied instrumentation instance.- Parameters:
instrumentation
- The instrumentation instance to validate.
-
isEnabled
protected boolean isEnabled()
Indicates that this redefinition strategy applies a modification of already loaded classes.- Returns:
true
if this redefinition strategy applies a modification of already loaded classes.
-
make
protected abstract AgentBuilder.RedefinitionStrategy.Collector make()
Creates a collector instance that is responsible for collecting loaded classes for potential retransformation.- Returns:
- A new collector for collecting already loaded classes for transformation.
-
apply
protected void apply(java.lang.instrument.Instrumentation instrumentation, AgentBuilder.Listener listener, AgentBuilder.CircularityLock circularityLock, AgentBuilder.PoolStrategy poolStrategy, AgentBuilder.LocationStrategy locationStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener, AgentBuilder.LambdaInstrumentationStrategy lambdaInstrumentationStrategy, AgentBuilder.DescriptionStrategy descriptionStrategy, AgentBuilder.FallbackStrategy fallbackStrategy, AgentBuilder.RawMatcher matcher)
Applies this redefinition strategy by submitting all loaded types to redefinition. If this redefinition strategy is disabled, this method is non-operational.- Parameters:
instrumentation
- The instrumentation instance to use.listener
- The listener to notify on transformations.circularityLock
- The circularity lock to use.poolStrategy
- The type locator to use.locationStrategy
- The location strategy to use.redefinitionDiscoveryStrategy
- The discovery strategy for loaded types to be redefined.redefinitionBatchAllocator
- The batch allocator for the redefinition strategy to apply.redefinitionListener
- The redefinition listener for the redefinition strategy to apply.lambdaInstrumentationStrategy
- A strategy to determine of theLambdaMetafactory
should be instrumented to allow for the instrumentation of classes that represent lambda expressions.descriptionStrategy
- The description strategy for resolving type descriptions for types.fallbackStrategy
- The fallback strategy to apply.matcher
- The matcher to identify what types to redefine.
-
-