Package net.bytebuddy.agent.builder
Class ResettableClassFileTransformer.WithDelegation
- java.lang.Object
-
- net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
-
- net.bytebuddy.agent.builder.ResettableClassFileTransformer.WithDelegation
-
- All Implemented Interfaces:
java.lang.instrument.ClassFileTransformer
,ResettableClassFileTransformer
- Direct Known Subclasses:
ResettableClassFileTransformer.WithDelegation.WithCallback
- Enclosing interface:
- ResettableClassFileTransformer
@Enhance public abstract static class ResettableClassFileTransformer.WithDelegation extends ResettableClassFileTransformer.AbstractBase
Implements a resettable class file transformer that allows for the delegation of a transformation. Typically implemented when using aAgentBuilder.TransformerDecorator
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ResettableClassFileTransformer.WithDelegation.Callback<T>
A callback that is invoked upon class file transformation.protected static class
ResettableClassFileTransformer.WithDelegation.Substitutable
A standard implementation of a substitutableResettableClassFileTransformer
.protected static class
ResettableClassFileTransformer.WithDelegation.WithCallback<T>
A class file transformer with a callback.-
Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.ResettableClassFileTransformer
ResettableClassFileTransformer.AbstractBase, ResettableClassFileTransformer.WithDelegation
-
-
Field Summary
Fields Modifier and Type Field Description protected ResettableClassFileTransformer
classFileTransformer
The class file transformer to delegate to.
-
Constructor Summary
Constructors Modifier Constructor Description protected
WithDelegation(ResettableClassFileTransformer classFileTransformer)
Creates a new delegating resettable class file transformer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> T
doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.java.util.Iterator<AgentBuilder.Transformer>
iterator(TypeDescription typeDescription, java.lang.ClassLoader classLoader, JavaModule module, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain)
Creates an iterator over the transformers that are applied for a given type.static ResettableClassFileTransformer
of(ResettableClassFileTransformer classFileTransformer, ResettableClassFileTransformer.WithDelegation.Callback<?> callback)
Creates a resettable class file transformer that wraps another transformer and adds a callback to the beginning and end of each transformation.boolean
reset(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener)
Deregisters this class file transformer and redefines any transformed class to its state without this class file transformer applied, if the supplied redefinition strategy is enabled.-
Methods inherited from class net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
reset, reset, reset, reset, reset, reset, reset
-
-
-
-
Field Detail
-
classFileTransformer
protected final ResettableClassFileTransformer classFileTransformer
The class file transformer to delegate to.
-
-
Constructor Detail
-
WithDelegation
protected WithDelegation(ResettableClassFileTransformer classFileTransformer)
Creates a new delegating resettable class file transformer.- Parameters:
classFileTransformer
- The class file transformer to delegate to.
-
-
Method Detail
-
doPrivileged
@Enhance private static <T> T doPrivileged(java.security.PrivilegedAction<T> action)
A proxy forjava.security.AccessController#doPrivileged
that is activated if available.- Type Parameters:
T
- The type of the action's resolved value.- Parameters:
action
- The action to execute from a privileged context.- Returns:
- The action's resolved value.
-
of
public static ResettableClassFileTransformer of(ResettableClassFileTransformer classFileTransformer, ResettableClassFileTransformer.WithDelegation.Callback<?> callback)
Creates a resettable class file transformer that wraps another transformer and adds a callback to the beginning and end of each transformation. If the module system is supported on the current JVM, the supplied module is retained.- Parameters:
classFileTransformer
- The class file transformer to delegate to.callback
- The callback to invoke.- Returns:
- A resettable class file transformer that delegates while also invoking the callback.
-
iterator
public java.util.Iterator<AgentBuilder.Transformer> iterator(TypeDescription typeDescription, @MaybeNull java.lang.ClassLoader classLoader, @MaybeNull JavaModule module, @MaybeNull java.lang.Class<?> classBeingRedefined, @MaybeNull java.security.ProtectionDomain protectionDomain)
Creates an iterator over the transformers that are applied for a given type.- Parameters:
typeDescription
- A description of a type.classLoader
- The type's class loader ornull
if the boot loader.module
- The type's module ornull
if the module system is not supported by the current VM.classBeingRedefined
- The class being redefined ornull
if the type is not yet loaded.protectionDomain
- The type's protection domain ornull
if not available.- Returns:
- An iterator over the transformers that are applied by this class file transformer if the given type is discovered.
-
reset
public boolean reset(java.lang.instrument.Instrumentation instrumentation, ResettableClassFileTransformer classFileTransformer, AgentBuilder.RedefinitionStrategy redefinitionStrategy, AgentBuilder.RedefinitionStrategy.DiscoveryStrategy redefinitionDiscoveryStrategy, AgentBuilder.RedefinitionStrategy.BatchAllocator redefinitionBatchAllocator, AgentBuilder.RedefinitionStrategy.Listener redefinitionListener)
Deregisters this class file transformer and redefines any transformed class to its state without this class file transformer applied, if the supplied redefinition strategy is enabled. If it is not enabled, only the
AgentBuilder.InstallationListener
is informed about the resetting without undoing any code changes.Note: A reset class file transformer should not be reinstalled. Instead, the
AgentBuilder
which built the transformer should be asked to install a new transformer.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()
.- Parameters:
instrumentation
- The instrumentation instance from which to deregister the transformer.classFileTransformer
- The actual class file transformer to deregister which might bethis
instance or any wrapper.redefinitionStrategy
- The redefinition to apply.redefinitionDiscoveryStrategy
- The discovery strategy for the types to reset.redefinitionBatchAllocator
- The batch allocator to use.redefinitionListener
- The redefinition listener to apply.- Returns:
true
if a reset was applied and this transformer was not previously removed.
-
-