这个规则集的顺序是什么
What makes the order of this ruleset
我目前正在学习 Drools 并阅读本书 Mastering JBoss Drools 6
在第4章的开头给出了一个例子来说明delete
关键字的使用。这是那个例子:
rule "Init current date"
when
then
insert(new Date());
end
rule "Expire coupons"
when
$now: Date()
$cp: Coupon(validUntil before $now)
then
delete($cp);
end
rule "Execute coupon"
when
$o: Order()
$cp: Coupon(order == $o)
then
System.out.println(" We have a coupon for this order!");
end
现在我的问题是:为什么 "Execute coupon" 规则比 "Expire coupon" 规则触发得晚。正如我了解到规则的顺序是不确定的,所以我认为 "Execute coupon" 规则可以在其他两个规则
之前触发
你是对的。根据我的经验,我什至会赌 "Execute coupon" 先触发,因为后面的规则通常会先触发。
很明显,这个例子必须通过
rule "Execute coupon"
when
$now: Date()
$o: Order()
$cp: Coupon(order == $o, validUntil after $now )
then
System.out.println(" We have a coupon for this order!");
end
或使用显着性(如果可能,应尽量避免)。
但是(我没有这本书)我也可以想象一个规则集可能按给定的方式工作的场景:
session.insert( new Date() );
session.insert( coupon );
session.fireAllRules();
session.insert( order );
session.fireAllRules();
我目前正在学习 Drools 并阅读本书 Mastering JBoss Drools 6
在第4章的开头给出了一个例子来说明delete
关键字的使用。这是那个例子:
rule "Init current date"
when
then
insert(new Date());
end
rule "Expire coupons"
when
$now: Date()
$cp: Coupon(validUntil before $now)
then
delete($cp);
end
rule "Execute coupon"
when
$o: Order()
$cp: Coupon(order == $o)
then
System.out.println(" We have a coupon for this order!");
end
现在我的问题是:为什么 "Execute coupon" 规则比 "Expire coupon" 规则触发得晚。正如我了解到规则的顺序是不确定的,所以我认为 "Execute coupon" 规则可以在其他两个规则
之前触发你是对的。根据我的经验,我什至会赌 "Execute coupon" 先触发,因为后面的规则通常会先触发。
很明显,这个例子必须通过
rule "Execute coupon"
when
$now: Date()
$o: Order()
$cp: Coupon(order == $o, validUntil after $now )
then
System.out.println(" We have a coupon for this order!");
end
或使用显着性(如果可能,应尽量避免)。
但是(我没有这本书)我也可以想象一个规则集可能按给定的方式工作的场景:
session.insert( new Date() );
session.insert( coupon );
session.fireAllRules();
session.insert( order );
session.fireAllRules();