Class FeatureProxy
java.lang.Object
cloud.opencode.base.feature.proxy.FeatureProxy
Feature Proxy
功能代理
Creates dynamic proxies that intercept methods annotated with @FeatureToggle.
创建动态代理,拦截带有@FeatureToggle注解的方法。
Features | 主要功能:
- Dynamic proxy creation - 动态代理创建
- Method-level feature gating - 方法级功能门控
- Context-aware evaluation - 上下文感知评估
- Default value support - 默认值支持
Usage Examples | 使用示例:
// Define interface with @FeatureToggle
public interface PaymentService {
@FeatureToggle("new-payment")
void processPayment(Order order);
@FeatureToggle(value = "refund-v2", defaultEnabled = false)
void processRefund(Order order);
}
// Create implementation
PaymentService impl = new PaymentServiceImpl();
// Create feature-gated proxy
PaymentService proxy = FeatureProxy.create(PaymentService.class, impl);
// Methods are only executed if feature is enabled
proxy.processPayment(order); // Only runs if "new-payment" is enabled
// With context supplier
PaymentService proxy = FeatureProxy.builder(PaymentService.class, impl)
.contextSupplier(() -> FeatureContext.ofUser(getCurrentUserId()))
.build();
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: N/A - 空值安全: 不适用
- Since:
- JDK 25, opencode-base-feature V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for FeatureProxy FeatureProxy构建器static enumBehavior when feature is disabled 功能禁用时的行为static classException thrown when feature is disabled and THROW_EXCEPTION behavior is set 当功能禁用且设置了THROW_EXCEPTION行为时抛出的异常 -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> FeatureProxy.Builder<T> Create a builder for more configuration options 创建构建器以获得更多配置选项static <T> TCreate a feature-gated proxy for an interface 为接口创建功能门控代理static <T> Tcreate(Class<T> interfaceType, T target, OpenFeature features) Create a feature-gated proxy with custom OpenFeature instance 使用自定义OpenFeature实例创建功能门控代理
-
Method Details
-
create
Create a feature-gated proxy for an interface 为接口创建功能门控代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceType- the interface class | 接口类target- the target implementation | 目标实现- Returns:
- proxied instance | 代理实例
-
create
Create a feature-gated proxy with custom OpenFeature instance 使用自定义OpenFeature实例创建功能门控代理- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceType- the interface class | 接口类target- the target implementation | 目标实现features- the OpenFeature instance | OpenFeature实例- Returns:
- proxied instance | 代理实例
-
builder
Create a builder for more configuration options 创建构建器以获得更多配置选项- Type Parameters:
T- the interface type | 接口类型- Parameters:
interfaceType- the interface class | 接口类target- the target implementation | 目标实现- Returns:
- new builder | 新的构建器
-