Table of Contents
属性 | 默认值 | 类型 | 描述 |
---|---|---|---|
no-loop |
false |
Boolean |
用来设定是否循环执行规则 |
ruleflow-group |
null |
String |
用来关联规则流与规则而实现规则的顺序执行。在某种层面上是对规则的分区执行。 |
salience |
0 |
Integer |
定义规则执行的优先级 |
agenda-group |
MAIN |
String |
分区执行规则, 不能与 ruleflow-group 同时存在。 |
auto-focus |
false |
Boolean |
控制在执行 MAIN agenda-group 之前执行其它 agenda-group 中的规则 |
lock-on-active |
false |
Boolean |
控制 agenda-group 与 ruleflow-group 中规则是否同时存在 |
date-effective |
null |
String |
规则在一段事件之后才可以被执行 |
date-expires |
null |
String |
规则在一段事件之内可以被执行 |
规则 - testLoop.drl
package org.drools.examples.loop;
import org.drools.examples.model.Cursor;
rule "no-loop testing"
no-loop true // will skip loop
when
c : Cursor(cur < 10, tmpCur : cur)
then
System.out.println(tmpCur);
c.setCur(c.getCur() + 1);
update(c);
end
执行代码 - Example_Loop.java
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules-no-loop");
Cursor cur = new Cursor(5);
kSession.insert(cur);
kSession.fireAllRules();
kSession.dispose();
规则 - testSalience.drl
package org.drools.examples.saliences;
rule "Rule 01"
salience -100
when
eval (true)
then
System.out.println("Rule 01");
end
rule "Rule 02"
when
eval (true)
then
System.out.println("Rule 02");
end
rule "Rule 03"
salience 100
when
eval (true)
then
System.out.println("Rule 03");
end
执行代码 - Example_Salience.java
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules-saliences");
kSession.fireAllRules();
kSession.dispose();
规则 - testPartition.drl
package org.drools.examples.partition;
rule "Rule 01"
agenda-group "partitionA"
when
eval (true)
then
System.out.println("Rule 01");
end
rule "Rule 02"
agenda-group "partitionB"
when
eval (true)
then
System.out.println("Rule 02");
end
执行代码 - Example_Partition.java
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules-partition");
kSession.getAgenda().getAgendaGroup("partitionB").setFocus();
kSession.fireAllRules();
kSession.getAgenda().getAgendaGroup("partitionA").setFocus();
kSession.fireAllRules();
kSession.dispose();
规则 - auto_focus.drl
package attributes
rule "auto-focus set to 'true'"
agenda-group "TEST"
auto-focus true
when
eval(true)
then
System.out.println(drools.getRule().getName());
end
执行代码 - Aattributes_auto_focus.java
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-attributes");
kSession.fireAllRules();
kSession.dispose();