Drools - rule hierarchy and conditional execution

吃可爱长大的小学妹 提交于 2019-12-03 13:38:09

问题


I was wondering if there is a way to define hierarchy (not just order of execution) between rules and control the rule execution - i.e. if the parent rule fired then the ones below should not be evaluated etc...

Information in this thread is an option but it is essentially IF/THEN/ELSE

Is there a different option?

thanks


回答1:


I am not sure if I understand your question, but using a combination of Activation Groups and the traditional conflict resolution strategies might achieve what you need. For instance, lets say you have 3 rules, A, B and C. You want to use, lets say, salience to give priority of execution to them in that order, and once one is executed, no other rule in that group should execute. You can define them like this:

rule A
    salience 30
    activation-group "x"
...

rule B
    salience 20
    activation-group "x"
...

rule C
    salience 10
    activation-group "x"
...

The salience guarantees that if A activates, it will fire first, followed by B, followed by C if they were activated. The Activation Group guarantees that once one of the rules fire, all other activated rules in that group will be cancelled. So, lets say that in your session, rules B and C activate, but not A, then B will fire and C will be cancelled.

Please note that activation groups do not prevent rules from later being re-activated. It just cancels any activations currently in the agenda at the time one of the rules in the group fire.



来源:https://stackoverflow.com/questions/10822512/drools-rule-hierarchy-and-conditional-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!