Drools 规则文件 ——语法属性

来源:互联网 发布:淘宝店铺标志300x300 编辑:程序博客网 时间:2024/05/18 02:11
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!");   end4.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!");   end6.dialect功能:规则当中要使用的语言类型 值:Java/mevl(默认为java)示例:rule "rule3" dialect "mvel" when     $app:Applicant(age == 24);  then     System.out.println("rule3----" + $app.name);end7.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"); endrule "rule2"    agenda-group "002" when  eval(true) then   System.out.println("rule2 execute");  end10: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"); endrule "rule2"    agenda-group "002"    auto-focus true when  eval(true) then   System.out.println("rule2 execute"); end


0 0
原创粉丝点击