Drools規(guī)則文件——語法屬性
-
salience
功能:設置規(guī)制執(zhí)行的優(yōu)先級
值:數(shù)字(數(shù)字越大執(zhí)行優(yōu)先級越高)示例:
rule "rule1" salience 1 when eval(true) then System.out.println("rule1"); end
-
no-loop
功能:控制已經(jīng)執(zhí)行的規(guī)則條件再次滿足是否再次執(zhí)行
值:true/false示例:
rule "rule1" no-loop true when $customer:Customer(name=="張三") then update($customer); System.out.println("customer name:"+$customer.getName()); end
-
date-effective
功能:當系統(tǒng)時間>=date-effective后才會觸發(fā),即設置規(guī)則生效時間。
值:日期默認格式為dd-MMM-yyyy,可以設置其它時間格式如yyyy-MM-dd,需在代碼設置系統(tǒng)時間格式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
-
date-expires
功能:當系統(tǒng)時間<=date-expires后才會觸發(fā),即設置規(guī)則過期時間。
值:日期默認格式為dd-MMM-yyyy可以設置其它時間格式如yyyy-MM-dd,需在代碼設置系統(tǒng)時間格式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
-
enabled
功能:設置規(guī)制是否可用
值:true/false示例:
rule "rule1" enabled false when eval(true); then System.out.println("rule1 is execution!"); end
-
dialect
功能:規(guī)則當中要使用的語言類型
值:Java/mevl(默認為java)示例:
rule "rule3" dialect "mvel" when $app:Applicant(age == 24); then System.out.println("rule3----" + $app.name); end
-
duration
功能:設置DRL文件開始執(zhí)行之后延遲多長時間開始執(zhí)行這條規(guī)則
值:一個長整型,單位是毫秒示例:
rule "rule1" duration 3000 when eval(true) then System.out.println("rule thread id:"+Thread.currentThread().getId()); end
-
activation-group
功能:若干個規(guī)則劃分成一個組
值:分組名稱示例:
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: 如果同一組規(guī)則,誰的salience高就執(zhí)行誰,沒有則按順序執(zhí)行最后同組最后那個規(guī)則
-
agenda-group
功能:Agenda Group 是用來在 Agenda的基礎之上,對現(xiàn)在的規(guī)則進行再次分組.Agenda Group 得到 Focus(焦點),這樣位于該 Agenda Group當中的規(guī)則才會
觸發(fā)執(zhí)行,否則將不執(zhí)行。
值:一個字符串示例:
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
-
auto-focus
功能:跟agenda-group一起使用,設置該規(guī)則是否可以自動獨取 Focus,如果該屬性設置為 true,那么在引擎執(zhí)行時,就不需要
顯示的為某個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