Class FeatureProxy

java.lang.Object
cloud.opencode.base.feature.proxy.FeatureProxy

public final class FeatureProxy extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static class 
    Builder for FeatureProxy FeatureProxy构建器
    static enum 
    Behavior when feature is disabled 功能禁用时的行为
    static class 
    Exception thrown when feature is disabled and THROW_EXCEPTION behavior is set 当功能禁用且设置了THROW_EXCEPTION行为时抛出的异常
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> FeatureProxy.Builder<T>
    builder(Class<T> interfaceType, T target)
    Create a builder for more configuration options 创建构建器以获得更多配置选项
    static <T> T
    create(Class<T> interfaceType, T target)
    Create a feature-gated proxy for an interface 为接口创建功能门控代理
    static <T> T
    create(Class<T> interfaceType, T target, OpenFeature features)
    Create a feature-gated proxy with custom OpenFeature instance 使用自定义OpenFeature实例创建功能门控代理

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static <T> T create(Class<T> interfaceType, T target)
      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

      public static <T> T create(Class<T> interfaceType, T target, OpenFeature features)
      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

      public static <T> FeatureProxy.Builder<T> builder(Class<T> interfaceType, T target)
      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 | 新的构建器