Package com.ultikits.ultitools.aop
Class ProxyFactory.InterceptorDispatcher
java.lang.Object
com.ultikits.ultitools.aop.ProxyFactory.InterceptorDispatcher
- All Implemented Interfaces:
InvocationHandler
- Enclosing class:
ProxyFactory
Dispatches intercepted calls to the
MethodInterceptor chain.
Implements the bootstrap-visible InvocationHandler rather than being bound as a
MethodDelegation target - see the class javadoc for why
a hard reference to this class in the generated proxy's bytecode is not safe to take.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<MethodInterceptor> private final ConcurrentHashMap<Method, Method> Caches the trampolineMethodper intercepted method. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ObjectinvokeTrampoline(Method trampoline, Object proxy, Object[] arguments) Invokes an already-resolved trampoline, and unwrapsInvocationTargetExceptionso checked exceptions reach the caller as their original type rather than wrapped - matching what a directsuper.method()call would have thrown.private MethodresolveTrampoline(Class<?> proxyClass, Method method)
-
Field Details
-
interceptors
-
trampolineCache
Caches the trampolineMethodper intercepted method. Safe to key on the method alone: one dispatcher instance is bound to exactly one generated class (seeProxyFactory.createProxyClass(java.lang.Class<T>, java.util.Set<java.lang.reflect.Method>)), soproxy.getClass()is invariant across every call this instance ever handles.
-
-
Constructor Details
-
InterceptorDispatcher
InterceptorDispatcher(List<MethodInterceptor> interceptors)
-
-
Method Details
-
invoke
- Specified by:
invokein interfaceInvocationHandler- Throws:
Throwable
-
resolveTrampoline
-
invokeTrampoline
private static Object invokeTrampoline(Method trampoline, Object proxy, Object[] arguments) throws Exception Invokes an already-resolved trampoline, and unwrapsInvocationTargetExceptionso checked exceptions reach the caller as their original type rather than wrapped - matching what a directsuper.method()call would have thrown. SeeSneakyThrowsfor why this needs a checked-exception-safe rethrow at all, and why it is not defined here.- Throws:
Exception
-