Drools 规则文件 ——语法属性

本文详细介绍了Drools规则引擎中关键特性的使用方法,包括优先级设置、循环控制、时间生效与失效、规则分组等。通过具体示例帮助读者更好地理解和应用这些特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.salience
功能:设置规制执行的优先级
值:数字(数字越大执行优先级越高)
示例:
rule "rule1" 
salience 1
when
eval(true)
then
System.out.println("rule1");
end


2.no-loop
功能:控制已经执行的规则条件再次满足是否再次执行
值:true/false
示例:
rule "rule1" 
no-loop true
when
$customer:Customer(name=="张三")
then
update($customer);
System.out.println("customer name:"+$customer.getName());
End


3.date-effective
功能:当系统时间>=date-effective后才会触发
值:日期默认格式为dd-MMM-yyyy,
可以设置其它时间格式如yyyy-MM-dd,需在代码设置系统时间格式System.setProperty("drools.dateformat", "yyyy-MM-dd");


示例:
rule "rule1" 
date-effective "2009-09-25"
when
eval(true);
then
System.out.println("rule1 is execution!");
end


4.date-expires
功能:当系统时间<=date-expires后才会触发
值:日期默认格式为dd-MMM-yyyy
可以设置其它时间格式如yyyy-MM-dd,需在代码设置系统时间格式System.setProperty("drools.dateformat", "yyyy-MM-dd");


示例:
rule "rule1" 
date-expires "2009-09-27"
when
eval(true);
then
System.out.println("rule1 is execution!");
end



5.enabled
功能:设置规制是否可用
值:true/false


示例:
rule "rule1" 
enabled false
when
eval(true);
then
System.out.println("rule1 is execution!");
end


6.dialect
功能:规则当中要使用的语言类型
值:Java/mevl(默认为java)


示例:
rule "rule3"
dialect "mvel"
when
$app:Applicant(age == 24);
then
System.out.println("rule3----" + $app.name);
end



7.duration
功能:设定时间之后在另外一个线程里触发
值:一个长整型,单位是毫秒


示例:
rule "rule1" 
duration 3000
when
eval(true)
then
System.out.println("rule thread id:"+Thread.currentThread().getId());
end


8.activation-group
功能:若干个规则划分成一个组
值:分组名称


示例:
rule "rule2"
activation-group "test"
salience 10
when
eval(true)
then
System.out.println("rule2 execute");
end

rule "rule1"
activation-group "test"
salience 9
when
eval(true)
then
System.out.println("rule1 execute");
end

note:
如果同一组规则,谁的salience高就执行谁,没有则按顺序执行最后同组最后那个规则


9.agenda-group
功能:Agenda Group 是用来在 Agenda的基础之上,对现在的规则进行再次分组.
Agenda Group 得到 Focus(焦点),这样位于该 Agenda Group当中的规则才会
触发执行,否则将不执行。
值:一个字符串


示例:
rule "rule1"
agenda-group "001"
when
eval(true)
then
System.out.println("rule1 execute");
end


rule "rule2"
agenda-group "002"
when
eval(true)
then
System.out.println("rule2 execute");

end


10:auto-focus
功能:跟agenda-group一起使用,设置该规则是否可以自动独取 Focus,如果该属性设置为 true,那么在引擎执行时,就不需要
显示的为某个Agenda Group 设置 Focus,否则需要。
值:true/false


示例:
rule "rule1"
agenda-group "001"
auto-focus true
when
eval(true)
then
System.out.println("rule1 execute");
end


rule "rule2"
agenda-group "002"
auto-focus true
when
eval(true)
then
System.out.println("rule2 execute");
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值