Class ProxyFactory
java.lang.Object
tech.guilhermekaua.spigotboot.core.proxy.ProxyFactory
Creates and caches proxy subclasses at runtime using
ProxyGenerator.
Supports non-final, non-primitive, non-array class targets.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectallocateWithoutConstructor(Class<?> proxyClass) Allocates a proxy instance without calling any constructor (viasun.misc.Unsafe).static <T> TcreateProxy(Class<T> target, Class<?>[] ctorArgTypes, Object[] ctorArgValues, MethodInterceptor handler) static <T> Class<? extends T>createProxyClass(Class<T> target) static ObjectinvokeDefault(Method method, Object self, Object[] args) Invokes the default-method body ofmethodonselfwithout virtual dispatch (which would re-enter the proxy override).
-
Constructor Details
-
ProxyFactory
public ProxyFactory()
-
-
Method Details
-
createProxyClass
- Parameters:
target- the class to proxy (must not be final, primitive, or array)- Returns:
- the generated proxy subclass, cached for subsequent calls
- Throws:
IllegalArgumentException- if the target cannot be proxied
-
createProxy
public static <T> T createProxy(Class<T> target, Class<?>[] ctorArgTypes, Object[] ctorArgValues, MethodInterceptor handler) - Parameters:
target- the class to proxyctorArgTypes- constructor parameter types, ornull/emptyfor no-argctorArgValues- constructor argument values matchingctorArgTypeshandler- the interceptor (must not be null)- Returns:
- a new proxy instance with the handler installed
- Throws:
RuntimeException- if constructor invocation fails
-
allocateWithoutConstructor
Allocates a proxy instance without calling any constructor (viasun.misc.Unsafe).- Parameters:
proxyClass- a proxy class returned bycreateProxyClass(java.lang.Class<T>)- Returns:
- an uninitialized instance
- Throws:
RuntimeException- if allocation fails
-
invokeDefault
Invokes the default-method body ofmethodonselfwithout virtual dispatch (which would re-enter the proxy override). Called by generated_proceed_methods; not intended as public API.- Parameters:
method- a default method declared on an interfaceself- the proxy instance implementing that interfaceargs- invocation arguments- Returns:
- whatever the default-method body returns
- Throws:
Throwable- anything the default-method body throws
-