Skip to content

defining rules listener

Mahmoud Ben Hassine edited this page May 17, 2017 · 6 revisions

You can listen to rule execution events through the RuleListener API:

public interface RuleListener {
    /**
     * Triggered before the evaluation of a rule.
     */
    boolean beforeEvaluate(Rule rule);
    /**
     * Triggered before a rule is executed.
     */
    void beforeExecute(Rule rule);
    /**
     * Triggered after a rule is executed successfully.
     */
    void onSuccess(Rule rule);
    /**
     * Triggered after a rule is executed with error.
     */
    void onFailure(Rule rule, Exception exception);
}

You can implement this interface to provide custom behavior to execute before/after each rule. To register your listener, use the following snippet:

RulesEngine rulesEngine = aNewRulesEngine()
    .withRuleListener(myRuleListener)
    .build();

You can register as many listeners as you want, they will be executed in their registration order.

Clone this wiki locally