Class OpenProxy
java.lang.Object
cloud.opencode.base.reflect.proxy.OpenProxy
Proxy Facade Entry Class
代理门面入口类
Provides common dynamic proxy operations API.
提供常用动态代理操作API。
Features | 主要功能:
- JDK dynamic proxy creation - JDK动态代理创建
- Proxy inspection - 代理检查
- Invocation handler utilities - 调用处理器工具
Usage Examples | 使用示例:
// Create proxy with interceptor
MyService proxy = OpenProxy.create(MyService.class, (p, method, args, invoker) -> {
System.out.println("Before: " + method.getName());
return invoker.invoke(args);
});
// Check if object is proxy
boolean isProxy = OpenProxy.isProxy(obj);
Security | 安全性:
- Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordMethod call record 方法调用记录static final recordRecording proxy wrapper 记录代理包装器 -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tcreate(Class<T> interfaceClass, MethodInterceptor interceptor) Creates a proxy for an interface with interceptor 为接口创建带拦截器的代理static <T> Tcreate(Class<T> interfaceClass, InvocationHandler handler) Creates a proxy for an interface with handler 为接口创建带处理器的代理static Objectcreate(InvocationHandler handler, Class<?>... interfaces) Creates a proxy for multiple interfaces 为多个接口创建代理static <T> TcreateNoOp(Class<T> interfaceClass) Creates a no-op proxy that returns default values 创建返回默认值的空操作代理static <T> OpenProxy.RecordingProxy<T> createRecording(Class<T> interfaceClass) Creates a mock proxy that records method calls 创建记录方法调用的模拟代理static <T> ProxyFactory<T> Creates a factory for building proxies 创建构建代理的工厂static InvocationHandlergetHandler(Object proxy) Gets the invocation handler of a proxy 获取代理的调用处理器static Class<?>[]getInterfaces(Object proxy) Gets the interfaces implemented by a proxy 获取代理实现的接口static booleanimplementsInterface(Object proxy, Class<?> interfaceClass) Checks if proxy implements an interface 检查代理是否实现接口static booleanChecks if an object is a proxy 检查对象是否为代理static <T> TUnwraps a proxy to get the underlying target 解包代理获取底层目标static <T> TCreates a proxy wrapping a target object 创建包装目标对象的代理static <T> Twrap(Class<T> interfaceClass, T target, MethodInterceptor interceptor) Creates a proxy wrapping a target with interceptor 创建带拦截器的包装目标对象的代理
-
Method Details
-
create
Creates a proxy for an interface with interceptor 为接口创建带拦截器的代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类interceptor- the method interceptor | 方法拦截器- Returns:
- the proxy | 代理
-
create
Creates a proxy for an interface with handler 为接口创建带处理器的代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类handler- the invocation handler | 调用处理器- Returns:
- the proxy | 代理
-
wrap
Creates a proxy wrapping a target object 创建包装目标对象的代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类target- the target object | 目标对象- Returns:
- the proxy | 代理
-
wrap
Creates a proxy wrapping a target with interceptor 创建带拦截器的包装目标对象的代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类target- the target object | 目标对象interceptor- the method interceptor | 方法拦截器- Returns:
- the proxy | 代理
-
create
Creates a proxy for multiple interfaces 为多个接口创建代理- Parameters:
handler- the invocation handler | 调用处理器interfaces- the interfaces | 接口- Returns:
- the proxy | 代理
-
factory
Creates a factory for building proxies 创建构建代理的工厂- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类- Returns:
- the factory | 工厂
-
isProxy
Checks if an object is a proxy 检查对象是否为代理- Parameters:
object- the object | 对象- Returns:
- true if proxy | 如果是代理返回true
-
getHandler
Gets the invocation handler of a proxy 获取代理的调用处理器- Parameters:
proxy- the proxy | 代理- Returns:
- the handler | 处理器
-
getInterfaces
-
implementsInterface
-
unwrap
Unwraps a proxy to get the underlying target 解包代理获取底层目标- Type Parameters:
T- the target type | 目标类型- Parameters:
proxy- the proxy | 代理- Returns:
- the target or null | 目标或null
-
createNoOp
Creates a no-op proxy that returns default values 创建返回默认值的空操作代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类- Returns:
- the proxy | 代理
-
createRecording
Creates a mock proxy that records method calls 创建记录方法调用的模拟代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceClass- the interface class | 接口类- Returns:
- the recording proxy | 记录代理
-