口水回缩导致规则不触发

发布于 2024-09-09 12:11:42 字数 750 浏览 7 评论 0原文

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

事实上,我有以下 A 列表: A1,属性 = 123 A2,属性 = 345 A3,property = 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”将删除A类具有属性为123的事实。当它到达“规则2”时,“listOfAs”不应该只有剩下的一个A(即属性设置为“345”的那个)。我注意到的是,“规则 2”根本不执行,即使我假设仍然有一个“A”对象尚未撤回。如果我注释掉“撤回”,它会很好地执行“规则2”。

我是否遗漏了这些规则的某些内容?

谢谢。 贾斯汀

I'm coming across some weird behavior in Drools 4.0.7, but maybe it's just cause I don't understand I how Drools works. Assume, there's a class "A" that has a property called "property".

As facts, I have the following list of A's:
A1, property = 123
A2, property = 345
A3, property = 123

I have two rules as follows:

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

My understanding is "Rule 1" will remove the facts of class A that have property to 123. When it gets to "Rule 2", shouldn't the "listOfAs" only have that one A that remains (i.e. the one where property is set to "345"). What I'm noticing is that "Rule 2" just doesn't execute at all even though I'm assuming there is still one "A" object that hasn't been retracted. If I comment out the "retract" it executes "Rule 2" fine.

Am I missing something about these rules work?

Thanks.
Justin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒中人 2024-09-16 12:11:43

我怀疑这里的问题是使用“lock-on-active”。鉴于第一个规则已激活,它会阻止其他规则也激活。

根据文档,lock-on-active 是:

“一个布尔值。“true”禁止在同一规则流或议程组中设置此标志的所有规则的额外激活。”

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."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文