简体   繁体   English

禁止其他流口水规则开除

[英]Disabling another drools rule from firing

Hi I want to disable some other drools rules from firing when another set of drools rules fire, how would you do that? 嗨,我想在其他一组流口水规则触发时禁止其他流口水规则触发,您将如何处理?

Say I have an agenda-group "Daily", which has two sets of drools rules set A has rules "Default-1", "Default-2", "Default-3" set B has rules "Custom-1", "Custom-2", "Custom-3" 假设我有一个议程组“每日”,其中有两套流口水规则,规则集A具有规则“ Default-1”,“ Default-2”,“ Default-3”,集合B具有规则“ Custom-1”,“ Custom-2”,“ Custom-3”

when the agenda-group "Daily" gets focused, and the current facts match the Custom pattern, I want "Custom-1" and/or "Custom-2" and/or "Custom-3" to fire only; 当议程组“每日”成为焦点,并且当前事实与“定制”模式匹配时,我只希望触发“ Custom-1”和/或“ Custom-2”和/或“ Custom-3”; otherwise, only "Default-1" and/or "Default-2" and/or "Default-3" fire. 否则,仅触发“ Default-1”和/或“ Default-2”和/或“ Default-3”。

Problem is, Default-1/2/3 are always fired. 问题是,始终会触发Default-1 / 2/3。 I need a way to disable them in Custom-1/2/3. 我需要一种在Custom-1 / 2/3中禁用它们的方法。 First, I set the salience level in Custom-1/2/3 to higher than Default-1/2/3. 首先,我将Custom-1 / 2/3中的显着性级别设置为高于Default-1 / 2/3。 Then I tried to use activation-group. 然后,我尝试使用激活组。 But if I set all of them to the same activation-group, only 1 out of the six rules will fire, thats not what I want. 但是,如果我将所有它们都设置为同一个激活组,那么六个规则中只有一个会触发,那不是我想要的。

I am not allowed to change the .java module, which loads all the rules everytime. 我不允许更改.java模块,该模块每次都会加载所有规则。 I can only change the .drl drools rules. 我只能更改.drl drools规则。

Thank you. 谢谢。

you could try solving your issue with marker objects. 您可以尝试使用标记对象解决问题。 suppose you define a Marker class: 假设您定义了一个Marker类:

public class Marker {
    String uniqueIdentifier;
    //getter and setter, etc
}

(drools allows you to define new classes in *.drl code without resorting to *.java) (drools允许您在* .drl代码中定义新类,而无需诉诸* .java)
then make the custom group run before the default group (salience would work, defining a flow would also work) and "mark" those objects for which a custom rule was triggered by inserting a new Marker fact into memory, something like this: 然后使自定义组在默认组之前运行(显着性将起作用,定义流也将起作用),并通过在内存中插入新的标记事实来“标记”那些已为其触发了自定义规则的对象,如下所示:

when
   SomeObject($unique: someIdentifier)
   //normal conditions
then
   insert(new Marker($unique))
   //normal action

and the in the default rules only act on objects for which no custom rule has fired: 而默认规则中的仅对未触发自定义规则的对象起作用:

when
   SomeObject($unique: someIdentifier)
   not Marker(uniqueIdentifier = $unique)
   //normal conditions
then
   //normal action

also, to prevent this from leaking you may need a 3rd (last) group of rules to clean up: 另外,为防止泄漏,您可能需要第三(最后)条规则进行清理:

when
   SomeObject($unique: someIdentifier)
   $marker : Marker(uniqueIdentifier = $unique)
then
   retract($marker)

The Drools support for this kind of behavior exists using Declarative Agenda . Drools使用声明性议程支持这种行为。

It basically provides this context methods: 它基本上提供了以下上下文方法:

void blockMatch(Match match);
void unblockAllMatches(Match match);
void cancelMatch(Match match);

To block other rules from within a rule while the rule blocking the others remains true or they're actually explicitly unblocked. 要在规则中阻止其他规则,而阻止其他规则仍然为true或实际上已明确取消阻止它们。

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

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