Class ProxyFactory<T>

java.lang.Object
cloud.opencode.base.reflect.proxy.ProxyFactory<T>
Type Parameters:
T - the primary interface type | 主接口类型

public class ProxyFactory<T> extends Object
Proxy Factory 代理工厂

Fluent factory for creating dynamic proxies with various configurations.

用于创建具有各种配置的动态代理的流式工厂。

Features | 主要功能:

  • Fluent proxy configuration API - 流式代理配置API
  • Multiple interface support - 多接口支持
  • Method-level interceptor binding - 方法级拦截器绑定
  • Target delegation - 目标委托

Usage Examples | 使用示例:

MyService proxy = ProxyFactory.forInterface(MyService.class)
    .target(realService)
    .intercept(loggingInterceptor)
    .create();

Security | 安全性:

  • Thread-safe: No (builder pattern, not thread-safe during construction) - 线程安全: 否(构建器模式,构建期间非线程安全)
  • Null-safe: No (caller must ensure non-null interface class) - 空值安全: 否(调用方须确保非空接口类)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • forInterface

      public static <T> ProxyFactory<T> forInterface(Class<T> interfaceClass)
      Creates a ProxyFactory for an interface 为接口创建ProxyFactory
      Type Parameters:
      T - the interface type | 接口类型
      Parameters:
      interfaceClass - the interface class | 接口类
      Returns:
      the factory | 工厂
    • implement

      public ProxyFactory<T> implement(Class<?> interfaceClass)
      Adds an additional interface 添加额外接口
      Parameters:
      interfaceClass - the interface class | 接口类
      Returns:
      this factory | 此工厂
    • classLoader

      public ProxyFactory<T> classLoader(ClassLoader classLoader)
      Sets the ClassLoader 设置ClassLoader
      Parameters:
      classLoader - the class loader | 类加载器
      Returns:
      this factory | 此工厂
    • target

      public ProxyFactory<T> target(Object target)
      Sets a target object for delegation 设置委托的目标对象
      Parameters:
      target - the target object | 目标对象
      Returns:
      this factory | 此工厂
    • intercept

      public ProxyFactory<T> intercept(MethodInterceptor interceptor)
      Sets the default interceptor 设置默认拦截器
      Parameters:
      interceptor - the interceptor | 拦截器
      Returns:
      this factory | 此工厂
    • intercept

      public ProxyFactory<T> intercept(String methodName, MethodInterceptor interceptor)
      Sets an interceptor for a specific method 为特定方法设置拦截器
      Parameters:
      methodName - the method name | 方法名
      interceptor - the interceptor | 拦截器
      Returns:
      this factory | 此工厂
    • intercept

      public ProxyFactory<T> intercept(String methodName, Class<?>[] parameterTypes, MethodInterceptor interceptor)
      Sets an interceptor for a specific method with parameter types 为特定方法(带参数类型)设置拦截器
      Parameters:
      methodName - the method name | 方法名
      parameterTypes - the parameter types | 参数类型
      interceptor - the interceptor | 拦截器
      Returns:
      this factory | 此工厂
    • handler

      public ProxyFactory<T> handler(InvocationHandler handler)
      Sets a custom invocation handler 设置自定义调用处理器
      Parameters:
      handler - the handler | 处理器
      Returns:
      this factory | 此工厂
    • create

      public T create()
      Creates the proxy 创建代理
      Returns:
      the proxy instance | 代理实例