简体   繁体   中英

Is it possible to unexpose a Rule in Drools?

Let's say I've a drools file like this,

rule "Test Rule 1"
salience 10

when
    $data : Map( this["amount"] >= 1000 && this["quantity"] >=3 )
then
    System.out.println("You've met the Criteria");
end

===========================================================================================

rule "Test Rule 2"
salience 9

when
    $data : Map( this["amount"] >= 1000 )
then
    System.out.println("Quantity Criteria is not met");
end

===========================================================================================

rule "Test Rule 3"
salience 8

when
    $data : Map( this["quantity"] >= 3 )
then
    System.out.println("Amount criteria is not met");
end

All these will be present in a single .drl file. As like in rule, order of rule will be based on highest Salience number. I need something like,

1) If Test Rule 1 is satisfied, I dont want further rules to be executed.

2) If Test Rule 1 is not satisfied, then I dont have to worry, it'll simply execute other rules in order of highest salience.

Is there any option like hideRule("Test Rule 2", "Test Rule 3") or hideRules() - which should unexpose rules waiting to be executed

I know I can alter my when condition to meet my criteria, but I would like to know if there is any option to unexpose a rule in Drools?

add drools.halt(); at the end of your Test Rule 1

An activation group will solve this:

An activation group is a set of rules bound together by the same "activation-group" rule attribute. In this group only one rule can fire, and after that rule has fired all the other rules are cancelled from the agenda. The clear() method can be called at any time, which cancels all of the activations before one has had a chance to fire.

Adding activation-group "groupName" to each of your rules should produce the behavior you are expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM