这种情况是:
- 获取与 DefaultAgendaEventListener 的 BeforeMatchFiredEvent 的匹配
- 判断比赛没用
- 我想取消规则,怎么做?
感谢帮助!
这种情况是:
感谢帮助!
您更改规则,以便在匹配无用时不会触发。
简单的例子——原始规则是这样的:
rule "Shirt is blue"
when
Shirt(color == "blue")
then
end
在这种情况下,当衬衫也是 XL 码时,匹配是“无用的”。因此,我们只需将规则定义更改为不允许 XL 衬衫。
rule "Shirt is blue (but not XL)"
when
Shirt(color == "blue", size != "XL")
then
end
或者,您可以使用标志/标记并检查它们的存在。这是一个简单的例子,我们进行了一些昂贵的调用来解决问题......
rule "Determine football jersey sale price"
when
$tournamentWinner: String()
$jersey : Jersey( price == null, team != $tournamentWinner )
then
$jersey.setPrice(19.99)
end
rule "Determine tournament winner"
salience 1
when
not(String())
$service: TeamDataService()
then
// assume this is an expensive call:
String $tournamentWinner = $service.getTournamentWinner()
// insert the results into working memory so the other 2 rules are now valid
insert($tournamentWinner)
end
rule "Special price for tournament winner"
when
$tournamentWinner: String()
$jersey: Jersey( price == null, team == $tournamentWinner)
then
$jersey.setPrice(25.00)
end
...或者您可以直接修改工作记忆以使规则不再有效:
rule "Apply discount"
when
$discount: Discount()
$cart: Cart( total > 0 )
then
$cart.apply($discount)
end
rule "Remove expired discounts"
salience 1
when
$discount: Discount(expired == true)
then
// Since the discount will no longer be in working memory, the other rule's match
// will be cancelled
retract($discount)
end
如果您尝试使用侦听器来修改匹配项,您最终会遇到并发修改异常。听众听;他们不修改。
如果您需要不匹配的规则,则需要编写它以使其不匹配。