简单规则中触发的规则是否不是基于优先级的排他性?
Are the rules fired in easy rules not exclusive based on priority?
我正在尝试使用 EasyRules。
我创建了 3 条规则 A、B 和 C,优先级分别为 1、2 和 3。
即使 规则 A 被评估为 true 并且具有最高优先级,但优先级较低的规则(即 B 和 C)是正在评估中。
此规则优先级如何运作?
如果优先级较高的规则被评估为真,那么优先级较低的规则就不会被评估,是否有变通办法?
优先级与规则是否执行无关。仅表示规则的执行顺序
来自documentation :
Each rule in Easy Rules has a priority. This represents the default
order in which registered rules are fired. By default, lower values
represent higher priorities.
您还可以阅读:
A composite rule is triggered if all conditions of its composing rules
are satisfied. When a composite rule is applied, actions of all
composing rules are performed in the natural order of rules which is
rules priorities by default.
如果您希望引擎在应用规则时跳过下一条规则,您应该使用 skipOnFirstAppliedRule
参数将引擎设置为 true
。
RulesEngine rulesEngine = RulesEngineBuilder.aNewRulesEngine()
.withSkipOnFirstAppliedRule(true)
.build();
// add your rules in the RulesEngine
rulesEngine.registerRule(new A());
rulesEngine.registerRule(new B());
rulesEngine.registerRule(new C());
// execute the rules
rulesEngine.fireRules();
在您的情况下,只会执行 A
规则。
我正在尝试使用 EasyRules。
我创建了 3 条规则 A、B 和 C,优先级分别为 1、2 和 3。
即使 规则 A 被评估为 true 并且具有最高优先级,但优先级较低的规则(即 B 和 C)是正在评估中。
此规则优先级如何运作?
如果优先级较高的规则被评估为真,那么优先级较低的规则就不会被评估,是否有变通办法?
优先级与规则是否执行无关。仅表示规则的执行顺序
来自documentation :
Each rule in Easy Rules has a priority. This represents the default order in which registered rules are fired. By default, lower values represent higher priorities.
您还可以阅读:
A composite rule is triggered if all conditions of its composing rules are satisfied. When a composite rule is applied, actions of all composing rules are performed in the natural order of rules which is rules priorities by default.
如果您希望引擎在应用规则时跳过下一条规则,您应该使用 skipOnFirstAppliedRule
参数将引擎设置为 true
。
RulesEngine rulesEngine = RulesEngineBuilder.aNewRulesEngine()
.withSkipOnFirstAppliedRule(true)
.build();
// add your rules in the RulesEngine
rulesEngine.registerRule(new A());
rulesEngine.registerRule(new B());
rulesEngine.registerRule(new C());
// execute the rules
rulesEngine.fireRules();
在您的情况下,只会执行 A
规则。