Drools規(guī)則文件——常用的語法屬性

Drools規(guī)則文件——語法屬性

  1. salience
    功能:設(shè)置規(guī)制執(zhí)行的優(yōu)先級
    值:數(shù)字(數(shù)字越大執(zhí)行優(yōu)先級越高)

    示例:

    rule "rule1"
      salience 1
      when
        eval(true)
      then  
        System.out.println("rule1");
    end
    
  2. 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
    
  3. date-effective
    功能:當系統(tǒng)時間>=date-effective后才會觸發(fā),即設(shè)置規(guī)則生效時間。
    值:日期默認格式為dd-MMM-yyyy,可以設(shè)置其它時間格式如yyyy-MM-dd,需在代碼設(shè)置系統(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
    
  4. date-expires
    功能:當系統(tǒng)時間<=date-expires后才會觸發(fā),即設(shè)置規(guī)則過期時間。
    值:日期默認格式為dd-MMM-yyyy可以設(shè)置其它時間格式如yyyy-MM-dd,需在代碼設(shè)置系統(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
    
  5. enabled
    功能:設(shè)置規(guī)制是否可用
    值:true/false

    示例:

    rule "rule1"
      enabled false
      when
        eval(true);
      then  
        System.out.println("rule1 is execution!");
    end
    
  6. dialect
    功能:規(guī)則當中要使用的語言類型
    值:Java/mevl(默認為java)

    示例:

    rule "rule3"
      dialect "mvel"
      when
        $app:Applicant(age == 24);
      then
        System.out.println("rule3----" + $app.name);
    end
    
  7. duration
    功能:設(shè)置DRL文件開始執(zhí)行之后延遲多長時間開始執(zhí)行這條規(guī)則
    值:一個長整型,單位是毫秒

    示例:

    rule "rule1"
      duration 3000
      when
        eval(true)
      then  
        System.out.println("rule thread id:"+Thread.currentThread().getId());
    end
    
  8. 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ī)則

  9. agenda-group
    功能:Agenda Group 是用來在 Agenda的基礎(chǔ)之上,對現(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
    
  10. auto-focus
    功能:跟agenda-group一起使用,設(shè)置該規(guī)則是否可以自動獨取 Focus,如果該屬性設(shè)置為 true,那么在引擎執(zhí)行時,就不需要
    顯示的為某個Agenda Group 設(shè)置 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
    

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容