3

我在 Drools 4.0.7 中遇到了一些奇怪的行为,但也许这只是因为我不明白 Drools 是如何工作的。假设有一个类“A”,它有一个名为“property”的属性。

事实上,我有以下 A 列表:A1,属性 = 123 A2,属性 = 345 A3,属性 = 123

我有两个规则如下:

rule "Rule 1 - Remove all A's that have property set to 123"
  salience 1000
  lock-on-active true
when
  $listOfAs : ArrayList collect(A( property == "123" ))
then
  for (Object a: $listOfAs ) {  
      retract (a)
  }
end

rule "Rule 2 - Do stuff with remaining A's"
  salience 900
  lock-on-active true
when
  $listOfAs : ArrayList collect(A())
then
...
end

我的理解是“规则 1”将删除具有 123 属性的 A 类的事实。当它到达“规则 2”时,“listOfAs”不应该只剩下一个 A(即属性是设置为“345”)。我注意到的是“规则 2”根本没有执行,即使我假设还有一个“A”对象没有被收回。如果我注释掉“撤回”,它会执行“规则 2”。

我错过了关于这些规则工作的一些东西吗?

谢谢。贾斯汀

4

1 回答 1

1

I suspect that the problem here is the use of 'lock-on-active'. Given that the first rule has activated, it prevents the other rule from also activating.

According to the docs lock-on-active is:

"A Boolean value. "true" inhibits additional activations of all rules with this flag set within the same ruleflow or agenda group."

于 2013-02-10T16:08:31.880 回答