Interface RuleListener
- All Known Implementing Classes:
LoggingRuleListener, MetricsListener, TracingRuleListener
public interface RuleListener
Rule Listener Interface - Observes Rule Execution Events
规则监听器接口 - 观察规则执行事件
Receives notifications about rule execution lifecycle events.
接收关于规则执行生命周期事件的通知。
Features | 主要功能:
- Before/after evaluation callbacks - 评估前/后回调
- Before/after execution callbacks - 执行前/后回调
- Failure notification - 失败通知
Usage Examples | 使用示例:
engine.addListener(new RuleListener() {
@Override
public void beforeEvaluate(Rule rule, RuleContext context) {
System.out.println("Evaluating: " + rule.getName());
}
});
Security | 安全性:
- Thread-safe: Implementation dependent - 线程安全: 取决于实现
- Null-safe: No (rule and context must not be null) - 空值安全: 否(规则和上下文不能为null)
- Since:
- JDK 25, opencode-base-rules V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidafterEvaluate(Rule rule, RuleContext context, boolean satisfied) Called after a rule is evaluated 在规则评估后调用default voidafterExecute(Rule rule, RuleContext context) Called after a rule is executed successfully 在规则成功执行后调用default voidbeforeEvaluate(Rule rule, RuleContext context) Called before a rule is evaluated 在规则评估前调用default voidbeforeExecute(Rule rule, RuleContext context) Called before a rule is executed 在规则执行前调用default voidonFailure(Rule rule, RuleContext context, Exception exception) Called when a rule execution fails 当规则执行失败时调用default voidonFinish(RuleContext context, int firedCount, long elapsedMillis) Called when rule engine finishes firing 当规则引擎完成触发时调用default voidonStart(RuleContext context) Called when rule engine starts firing 当规则引擎开始触发时调用
-
Method Details
-
beforeEvaluate
Called before a rule is evaluated 在规则评估前调用- Parameters:
rule- the rule | 规则context- the context | 上下文
-
afterEvaluate
Called after a rule is evaluated 在规则评估后调用- Parameters:
rule- the rule | 规则context- the context | 上下文satisfied- whether the condition was satisfied | 条件是否满足
-
beforeExecute
Called before a rule is executed 在规则执行前调用- Parameters:
rule- the rule | 规则context- the context | 上下文
-
afterExecute
Called after a rule is executed successfully 在规则成功执行后调用- Parameters:
rule- the rule | 规则context- the context | 上下文
-
onFailure
Called when a rule execution fails 当规则执行失败时调用- Parameters:
rule- the rule | 规则context- the context | 上下文exception- the exception | 异常
-
onStart
Called when rule engine starts firing 当规则引擎开始触发时调用- Parameters:
context- the context | 上下文
-
onFinish
Called when rule engine finishes firing 当规则引擎完成触发时调用- Parameters:
context- the context | 上下文firedCount- number of rules fired | 触发的规则数量elapsedMillis- execution time in milliseconds | 执行时间(毫秒)
-