Class ProxyFactory

java.lang.Object
tech.guilhermekaua.spigotboot.core.proxy.ProxyFactory

public final class ProxyFactory extends Object
Creates and caches proxy subclasses at runtime using ProxyGenerator. Supports non-final, non-primitive, non-array class targets.
  • Constructor Details

    • ProxyFactory

      public ProxyFactory()
  • Method Details

    • createProxyClass

      public static <T> Class<? extends T> createProxyClass(Class<T> target)
      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 proxy
      ctorArgTypes - constructor parameter types, or null/empty for no-arg
      ctorArgValues - constructor argument values matching ctorArgTypes
      handler - the interceptor (must not be null)
      Returns:
      a new proxy instance with the handler installed
      Throws:
      RuntimeException - if constructor invocation fails
    • allocateWithoutConstructor

      public static Object allocateWithoutConstructor(Class<?> proxyClass)
      Allocates a proxy instance without calling any constructor (via sun.misc.Unsafe).
      Parameters:
      proxyClass - a proxy class returned by createProxyClass(java.lang.Class<T>)
      Returns:
      an uninitialized instance
      Throws:
      RuntimeException - if allocation fails
    • invokeDefault

      public static Object invokeDefault(Method method, Object self, Object[] args) throws Throwable
      Invokes the default-method body of method on self without 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 interface
      self - the proxy instance implementing that interface
      args - invocation arguments
      Returns:
      whatever the default-method body returns
      Throws:
      Throwable - anything the default-method body throws