public abstract class InvocationHandlerAdapter extends Object implements Implementation
InvocationHandler
. The adapter allows the invocation handler
to also intercept method calls to non-interface methods.Modifier and Type | Class and Description |
---|---|
protected static interface |
InvocationHandlerAdapter.AssignerConfigurable
Allows for the configuration of an
Assigner
of an InvocationHandlerAdapter . |
protected static class |
InvocationHandlerAdapter.ForInstanceDelegation
An implementation of an
InvocationHandlerAdapter that delegates method
invocations to an adapter that is stored in an instance field. |
protected static class |
InvocationHandlerAdapter.ForStaticDelegation
An implementation of an
InvocationHandlerAdapter that delegates method
invocations to an adapter that is stored in a static field. |
Implementation.Compound, Implementation.Context, Implementation.Simple, Implementation.SpecialMethodInvocation, Implementation.Target
Modifier and Type | Field and Description |
---|---|
protected Assigner |
assigner
The assigner that is used for assigning the return invocation handler's return value to the
intercepted method's return value.
|
protected boolean |
cacheMethods
Determines if the
Method instances that are handed to the intercepted methods are
cached in static fields. |
protected static boolean |
CACHING
Indicates that a
Method should be cached. |
protected String |
fieldName
The name of the field for storing an invocation handler.
|
Modifier | Constructor and Description |
---|---|
protected |
InvocationHandlerAdapter(String fieldName,
boolean cacheMethods,
Assigner assigner)
Creates a new invocation handler for a given field.
|
Modifier and Type | Method and Description |
---|---|
protected ByteCodeAppender.Size |
apply(MethodVisitor methodVisitor,
Implementation.Context implementationContext,
MethodDescription instrumentedMethod,
TypeDescription instrumentedType,
StackManipulation preparingManipulation)
Applies an implementation that delegates to a invocation handler.
|
boolean |
equals(Object other) |
int |
hashCode() |
static InvocationHandlerAdapter |
of(InvocationHandler invocationHandler)
Creates an implementation for any instance of an
InvocationHandler that delegates
all method interceptions to the given instance which will be stored in a static field. |
static InvocationHandlerAdapter |
of(InvocationHandler invocationHandler,
String fieldName)
Creates an implementation for any instance of an
InvocationHandler that delegates
all method interceptions to the given instance which will be stored in a static field. |
static InvocationHandlerAdapter |
toInstanceField(String fieldName)
Creates an implementation for any
InvocationHandler that delegates
all method interceptions to a public instance field with the given name. |
abstract InvocationHandlerAdapter.AssignerConfigurable |
withMethodCache()
By default, any
Method instance that is handed over to an
InvocationHandler is created on each invocation of the method. |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
appender, prepare
protected static final boolean CACHING
Method
should be cached.protected final String fieldName
protected final Assigner assigner
protected final boolean cacheMethods
Method
instances that are handed to the intercepted methods are
cached in static
fields.protected InvocationHandlerAdapter(String fieldName, boolean cacheMethods, Assigner assigner)
fieldName
- The name of the field.cacheMethods
- Determines if the Method
instances that are handed to the
intercepted methods are cached in static
fields.assigner
- The assigner to apply when defining this implementation.public static InvocationHandlerAdapter of(InvocationHandler invocationHandler)
InvocationHandler
that delegates
all method interceptions to the given instance which will be stored in a static
field.invocationHandler
- The invocation handler to which all method calls are delegated.public static InvocationHandlerAdapter of(InvocationHandler invocationHandler, String fieldName)
InvocationHandler
that delegates
all method interceptions to the given instance which will be stored in a static
field.invocationHandler
- The invocation handler to which all method calls are delegated.fieldName
- The name of the field.public static InvocationHandlerAdapter toInstanceField(String fieldName)
InvocationHandler
that delegates
all method interceptions to a public
instance field with the given name. This field has to be
set before any invocations are intercepted. Otherwise, a NullPointerException
will be
thrown.fieldName
- The name of the field.public abstract InvocationHandlerAdapter.AssignerConfigurable withMethodCache()
Method
instance that is handed over to an
InvocationHandler
is created on each invocation of the method.
Method
look-ups are normally cached by its defining Class
what
makes a repeated look-up of a method little expensive. However, because Method
instances are mutable by their AccessibleObject
contact, any looked-up instance
needs to be copied by its defining Class
before exposing it. This can cause performance
deficits when a method is for example called repeatedly in a loop. By enabling the method cache, this
performance penalty can be avoided by caching a single Method
instance for
any intercepted method as a static
field in the instrumented type.Method
instance
in form of a static
field.protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod, TypeDescription instrumentedType, StackManipulation preparingManipulation)
methodVisitor
- The method visitor for writing the byte code to.implementationContext
- The implementation context for the current implementation.instrumentedMethod
- The method that is instrumented.instrumentedType
- The type that is instrumented.preparingManipulation
- A stack manipulation that applies any preparation to the operand stack.Copyright © 2014–2015. All rights reserved.