Class TracingRuleListener
java.lang.Object
cloud.opencode.base.rules.trace.TracingRuleListener
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterEvaluate(Rule rule, RuleContext context, boolean satisfied) Called after a rule is evaluated 在规则评估后调用voidafterExecute(Rule rule, RuleContext context) Called after a rule is executed successfully 在规则成功执行后调用voidbeforeEvaluate(Rule rule, RuleContext context) Called before a rule is evaluated 在规则评估前调用getTrace()Returns the assembled execution trace after engine.fire() completes 在engine.fire()完成后返回组装好的执行轨迹voidonFailure(Rule rule, RuleContext context, Exception exception) Called when a rule execution fails 当规则执行失败时调用voidonFinish(RuleContext context, int firedCount, long elapsedMillis) Called when rule engine finishes firing 当规则引擎完成触发时调用voidonStart(RuleContext context) Called when rule engine starts firing 当规则引擎开始触发时调用voidreset()Clears all state for reuse 清除所有状态以便重用Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface RuleListener
beforeExecute
-
Constructor Details
-
TracingRuleListener
public TracingRuleListener()
-
-
Method Details
-
onStart
Description copied from interface:RuleListenerCalled when rule engine starts firing 当规则引擎开始触发时调用- Specified by:
onStartin interfaceRuleListener- Parameters:
context- the context | 上下文
-
beforeEvaluate
Description copied from interface:RuleListenerCalled before a rule is evaluated 在规则评估前调用- Specified by:
beforeEvaluatein interfaceRuleListener- Parameters:
rule- the rule | 规则context- the context | 上下文
-
afterEvaluate
Description copied from interface:RuleListenerCalled after a rule is evaluated 在规则评估后调用- Specified by:
afterEvaluatein interfaceRuleListener- Parameters:
rule- the rule | 规则context- the context | 上下文satisfied- whether the condition was satisfied | 条件是否满足
-
afterExecute
Description copied from interface:RuleListenerCalled after a rule is executed successfully 在规则成功执行后调用- Specified by:
afterExecutein interfaceRuleListener- Parameters:
rule- the rule | 规则context- the context | 上下文
-
onFailure
Description copied from interface:RuleListenerCalled when a rule execution fails 当规则执行失败时调用- Specified by:
onFailurein interfaceRuleListener- Parameters:
rule- the rule | 规则context- the context | 上下文exception- the exception | 异常
-
onFinish
Description copied from interface:RuleListenerCalled when rule engine finishes firing 当规则引擎完成触发时调用- Specified by:
onFinishin interfaceRuleListener- Parameters:
context- the context | 上下文firedCount- number of rules fired | 触发的规则数量elapsedMillis- execution time in milliseconds | 执行时间(毫秒)
-
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 清除所有状态以便重用
-