Class TracingRuleListener

java.lang.Object
cloud.opencode.base.rules.trace.TracingRuleListener
All Implemented Interfaces:
RuleListener

public class TracingRuleListener extends Object implements RuleListener
Tracing Rule Listener - Collects Execution Data to Build an ExecutionTrace 追踪规则监听器 - 收集执行数据以构建执行轨迹

Records timing, condition results, execution status, and errors for each rule during a single engine fire() call. After the engine completes, call getTrace() to retrieve the assembled ExecutionTrace.

在单次引擎fire()调用期间,记录每个规则的计时、条件结果、执行状态和错误。 引擎完成后,调用getTrace()获取组装好的ExecutionTrace

Thread Safety | 线程安全:

This listener is designed for single-threaded use within one fire() call. It uses simple collections (ArrayList, HashMap) since a single fire() call is single-threaded.

此监听器设计用于单次fire()调用中的单线程使用。 它使用简单集合(ArrayList、HashMap),因为单次fire()调用是单线程的。

Since:
JDK 25, opencode-base-rules V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • TracingRuleListener

      public TracingRuleListener()
  • Method Details

    • onStart

      public void onStart(RuleContext context)
      Description copied from interface: RuleListener
      Called when rule engine starts firing 当规则引擎开始触发时调用
      Specified by:
      onStart in interface RuleListener
      Parameters:
      context - the context | 上下文
    • beforeEvaluate

      public void beforeEvaluate(Rule rule, RuleContext context)
      Description copied from interface: RuleListener
      Called before a rule is evaluated 在规则评估前调用
      Specified by:
      beforeEvaluate in interface RuleListener
      Parameters:
      rule - the rule | 规则
      context - the context | 上下文
    • afterEvaluate

      public void afterEvaluate(Rule rule, RuleContext context, boolean satisfied)
      Description copied from interface: RuleListener
      Called after a rule is evaluated 在规则评估后调用
      Specified by:
      afterEvaluate in interface RuleListener
      Parameters:
      rule - the rule | 规则
      context - the context | 上下文
      satisfied - whether the condition was satisfied | 条件是否满足
    • afterExecute

      public void afterExecute(Rule rule, RuleContext context)
      Description copied from interface: RuleListener
      Called after a rule is executed successfully 在规则成功执行后调用
      Specified by:
      afterExecute in interface RuleListener
      Parameters:
      rule - the rule | 规则
      context - the context | 上下文
    • onFailure

      public void onFailure(Rule rule, RuleContext context, Exception exception)
      Description copied from interface: RuleListener
      Called when a rule execution fails 当规则执行失败时调用
      Specified by:
      onFailure in interface RuleListener
      Parameters:
      rule - the rule | 规则
      context - the context | 上下文
      exception - the exception | 异常
    • onFinish

      public void onFinish(RuleContext context, int firedCount, long elapsedMillis)
      Description copied from interface: RuleListener
      Called when rule engine finishes firing 当规则引擎完成触发时调用
      Specified by:
      onFinish in interface RuleListener
      Parameters:
      context - the context | 上下文
      firedCount - number of rules fired | 触发的规则数量
      elapsedMillis - execution time in milliseconds | 执行时间(毫秒)
    • getTrace

      public ExecutionTrace getTrace()
      Returns the assembled execution trace after engine.fire() completes 在engine.fire()完成后返回组装好的执行轨迹

      Must be called after the engine has finished firing rules.

      必须在引擎完成触发规则后调用。

      Returns:
      the execution trace | 执行轨迹
    • reset

      public void reset()
      Clears all state for reuse 清除所有状态以便重用