嗨,我想禁止其他drools规则在另一组drools规则触发时触发,你会怎么做?
假设我有一个议程组"Daily",它有两组drools规则集A有规则"Default-1“、"Default-2”、"Default-3“集B有规则"Custom-1”、"Custom-2“、"Custom-3”
当议程组"Daily“获得关注,并且当前事实与自定义模式匹配时,我希望" Custom -1”和/或"Custom-2“和/或"Custom-3”只触发;否则,只触发"Default-1“和/或"Default-2”和/或"Default-3“。
问题是,默认的-1/2/3总是被触发。我需要一种方法在Custom-1/2/3中禁用它们。首先,我将Custom-1/2/3中的显着性级别设置为高于默认值-1/2/3。然后我尝试使用激活组。但是如果我将它们都设置到同一个激活组,那么六条规则中只有一条会触发,这不是我想要的。
我不允许更改.java模块,它每次都会加载所有规则。我只能更改.drl drools的规则。
谢谢。
发布于 2013-01-11 14:40:22
您可以尝试使用标记对象来解决您的问题。假设您定义了一个Marker类:
public class Marker {
String uniqueIdentifier;
//getter and setter, etc
}(drools允许您在不求助于*.java的情况下在*.drl代码中定义新类)
然后使定制组在默认组之前运行(显着性将起作用,定义流也将起作用),并通过将新的标记事实插入到内存中来“标记”那些触发了自定义规则的对象,如下所示:
when
SomeObject($unique: someIdentifier)
//normal conditions
then
insert(new Marker($unique))
//normal action默认规则中的仅作用于尚未触发自定义规则的对象:
when
SomeObject($unique: someIdentifier)
not Marker(uniqueIdentifier = $unique)
//normal conditions
then
//normal action此外,为了防止泄漏,您可能需要第三组(最后一组)规则来清理:
when
SomeObject($unique: someIdentifier)
$marker : Marker(uniqueIdentifier = $unique)
then
retract($marker)发布于 2016-02-02 08:30:57
Drools对这种行为的支持是通过Declarative Agenda实现的。
它基本上提供了这个上下文方法:
void blockMatch(Match match);
void unblockAllMatches(Match match);
void cancelMatch(Match match);阻止来自规则中的其他规则,而阻止其他规则的规则仍然是true,或者它们实际上是显式解锁的。
https://stackoverflow.com/questions/14272944
复制相似问题