简体   繁体   English

是否可以在Drools中不公开规则?

[英]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. 所有这些都将存在于单个.drl文件中。 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. 1)如果满足Test Rule 1 ,我不希望执行其他规则。

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. 2)如果不满足Test Rule 1 ,那么我不必担心,它会按照最高显着性的顺序执行其他规则。

Is there any option like hideRule("Test Rule 2", "Test Rule 3") or hideRules() - which should unexpose rules waiting to be executed 是否有诸如hideRule("Test Rule 2", "Test Rule 3")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? 我知道我可以更改何时满足我的条件,但是我想知道在Drools中是否有不unexpose规则的选项?

add drools.halt(); 添加drools.halt(); at the end of your Test Rule 1 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. 可以随时调用clear()方法,该方法会在有机会触发之前取消所有激活。

Adding activation-group "groupName" to each of your rules should produce the behavior you are expecting. activation-group "groupName"添加到每个规则中应该会产生预期的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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