Package net.bytebuddy.agent.builder
Class ResettableClassFileTransformer.WithDelegation.Substitutable
- java.lang.Object
-
- net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
-
- net.bytebuddy.agent.builder.ResettableClassFileTransformer.WithDelegation.Substitutable
-
- All Implemented Interfaces:
java.lang.instrument.ClassFileTransformer,ResettableClassFileTransformer,ResettableClassFileTransformer.Substitutable
- Enclosing class:
- ResettableClassFileTransformer.WithDelegation
@Enhance protected static class ResettableClassFileTransformer.WithDelegation.Substitutable extends ResettableClassFileTransformer.AbstractBase implements ResettableClassFileTransformer.Substitutable
A standard implementation of a substitutableResettableClassFileTransformer.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceResettableClassFileTransformer.WithDelegation.Substitutable.FactoryA factory for creating a subclass ofResettableClassFileTransformer.WithDelegation.Substitutablethat supports the module system, if available.-
Nested classes/interfaces inherited from interface net.bytebuddy.agent.builder.ResettableClassFileTransformer
ResettableClassFileTransformer.AbstractBase, ResettableClassFileTransformer.Substitutable, ResettableClassFileTransformer.WithDelegation
-
-
Field Summary
Fields Modifier and Type Field Description protected ResettableClassFileTransformerclassFileTransformerThe class file transformer to delegate to.private static ResettableClassFileTransformer.WithDelegation.Substitutable.FactoryDISPATCHERA dispatcher for invoking the correct transformer method.
-
Constructor Summary
Constructors Modifier Constructor Description protectedSubstitutable(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 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.Substitutableof(ResettableClassFileTransformer classFileTransformer)Creates a new substitutable class file transformer of another class file transformer.booleanreset(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.voidsubstitute(ResettableClassFileTransformer classFileTransformer)Substitutes the current class file transformer.byte[]transform(java.lang.ClassLoader classLoader, java.lang.String internalName, java.lang.Class<?> classBeingRedefined, java.security.ProtectionDomain protectionDomain, byte[] binaryRepresentation)ResettableClassFileTransformerunwrap()Returns the underlying non-substitutable class file transformer.-
Methods inherited from class net.bytebuddy.agent.builder.ResettableClassFileTransformer.AbstractBase
reset, reset, reset, reset, reset, reset, reset
-
-
-
-
Field Detail
-
DISPATCHER
private static final ResettableClassFileTransformer.WithDelegation.Substitutable.Factory DISPATCHER
A dispatcher for invoking the correct transformer method.
-
classFileTransformer
protected volatile ResettableClassFileTransformer classFileTransformer
The class file transformer to delegate to.
-
-
Constructor Detail
-
Substitutable
protected Substitutable(ResettableClassFileTransformer classFileTransformer)
Creates a new delegating resettable class file transformer.- Parameters:
classFileTransformer- The class file transformer to delegate to.
-
-
Method Detail
-
of
public static ResettableClassFileTransformer.Substitutable of(ResettableClassFileTransformer classFileTransformer)
Creates a new substitutable class file transformer of another class file transformer.- Parameters:
classFileTransformer- The class file transformer to wrap.- Returns:
- A substitutable version of the supplied class file transformer.
-
substitute
public void substitute(ResettableClassFileTransformer classFileTransformer)
Substitutes the current class file transformer.- Specified by:
substitutein interfaceResettableClassFileTransformer.Substitutable- Parameters:
classFileTransformer- The class file transformer to use.
-
unwrap
public ResettableClassFileTransformer unwrap()
Returns the underlying non-substitutable class file transformer.- Specified by:
unwrapin interfaceResettableClassFileTransformer.Substitutable- Returns:
- The underlying non-substitutable class file transformer.
-
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.- Specified by:
iteratorin interfaceResettableClassFileTransformer- Parameters:
typeDescription- A description of a type.classLoader- The type's class loader ornullif the boot loader.module- The type's module ornullif the module system is not supported by the current VM.classBeingRedefined- The class being redefined ornullif the type is not yet loaded.protectionDomain- The type's protection domain ornullif 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.InstallationListeneris informed about the resetting without undoing any code changes.Note: A reset class file transformer should not be reinstalled. Instead, the
AgentBuilderwhich 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().- Specified by:
resetin interfaceResettableClassFileTransformer- Parameters:
instrumentation- The instrumentation instance from which to deregister the transformer.classFileTransformer- The actual class file transformer to deregister which might bethisinstance 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:
trueif a reset was applied and this transformer was not previously removed.
-
transform
public byte[] transform(@MaybeNull java.lang.ClassLoader classLoader, @MaybeNull java.lang.String internalName, @MaybeNull java.lang.Class<?> classBeingRedefined, @MaybeNull java.security.ProtectionDomain protectionDomain, byte[] binaryRepresentation) throws java.lang.instrument.IllegalClassFormatException
- Specified by:
transformin interfacejava.lang.instrument.ClassFileTransformer- Throws:
java.lang.instrument.IllegalClassFormatException
-
-