Class MetricsFeatureListener

java.lang.Object
cloud.opencode.base.feature.audit.MetricsFeatureListener
All Implemented Interfaces:
FeatureListener

public class MetricsFeatureListener extends Object implements FeatureListener
Metrics Feature Listener 指标功能监听器

Listener that collects metrics on feature changes.

收集功能变更指标的监听器。

Features | 主要功能:

  • Change counting - 变更计数
  • Enable/Disable tracking - 启用/禁用跟踪
  • Per-feature metrics - 按功能指标

Usage Examples | 使用示例:

MetricsFeatureListener metrics = new MetricsFeatureListener();
OpenFeature.getInstance().addListener(metrics);

// Later, get metrics
long totalChanges = metrics.getTotalChanges();
long enableCount = metrics.getEnableCount("feature-key");

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-feature V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • MetricsFeatureListener

      public MetricsFeatureListener()
  • Method Details

    • onFeatureChanged

      public void onFeatureChanged(String key, boolean oldValue, boolean newValue)
      Description copied from interface: FeatureListener
      Called when a feature's enabled state changes 当功能的启用状态改变时调用
      Specified by:
      onFeatureChanged in interface FeatureListener
      Parameters:
      key - the feature key | 功能键
      oldValue - the old enabled state | 旧的启用状态
      newValue - the new enabled state | 新的启用状态
    • getTotalChanges

      public long getTotalChanges()
      Get total number of changes 获取总变更数
      Returns:
      total changes | 总变更数
    • getEnableCount

      public long getEnableCount(String key)
      Get enable count for a feature 获取功能的启用次数
      Parameters:
      key - the feature key | 功能键
      Returns:
      enable count | 启用次数
    • getDisableCount

      public long getDisableCount(String key)
      Get disable count for a feature 获取功能的禁用次数
      Parameters:
      key - the feature key | 功能键
      Returns:
      disable count | 禁用次数
    • getAllEnableCounts

      public Map<String,Long> getAllEnableCounts()
      Get all enable counts 获取所有启用计数
      Returns:
      map of feature key to enable count | 功能键到启用计数的映射
    • getAllDisableCounts

      public Map<String,Long> getAllDisableCounts()
      Get all disable counts 获取所有禁用计数
      Returns:
      map of feature key to disable count | 功能键到禁用计数的映射
    • reset

      public void reset()
      Reset all metrics 重置所有指标