关于规则文件drl中的ruleflow-group属性的实用,请教?
|
aimer311
2008-07-01
设置规则执行顺序的两种方法:
1、salience 这个比较容易理解 2、ruleflow-group,先在规则文件中设置组别,再在rf文件中定义规则组的执行顺序。 请看规则文件user.drl的部分定义: rule "userRule" #include attributes such as "salience" here... no-loop true #salience 98 ruleflow-group 'group1' when name is alice #$user : User(name == "alice") then delete user; #UserAction ua = new UserAction(); #ua.userFilter(users,$user); end rule "sqlRule" #include attributes such as "salience" here... no-loop true #salience 99 ruleflow-group 'group2' when #only aimer can execute the sql #$user : User(name == "aimer") name is aimer then #execute sql. #UserAction ua = new UserAction(); #ua.execute(params); execute sql with params; end 加载规则文件代码如下:
Reader source = new InputStreamReader( getClass().getResourceAsStream( "/rules/user.drl" ) );
Reader dsl = new InputStreamReader(getClass().getResourceAsStream("/rules/user.dsl"));
PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl(source, dsl);
//builder.addPackageFromDrl( source );
source = new InputStreamReader(getClass().getResourceAsStream("/rules/test.rfm"));
builder.addRuleFlow(source);
但是打印的信息显示并没有执行规则,或者规则执行不正确,没有出错信息。我用salience设置的话可以出现正确的结果。 rfm文件如下:
<org.drools.ruleflow.core.impl.RuleFlowProcessImpl id="1">
<nodes id="2">
<entry>
<long>1</long>
<org.drools.ruleflow.core.impl.StartNodeImpl id="3">
<id>1</id>
<name>Start</name>
<incomingConnections id="4"/>
<outgoingConnections id="5">
<org.drools.ruleflow.core.impl.ConnectionImpl id="6">
<type>1</type>
<from class="org.drools.ruleflow.core.impl.StartNodeImpl" reference="3"/>
<to class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" id="7">
<ruleFlowGroup>group1</ruleFlowGroup>
<id>4</id>
<name>RuleSet</name>
<incomingConnections id="8">
<org.drools.ruleflow.core.impl.ConnectionImpl reference="6"/>
</incomingConnections>
<outgoingConnections id="9">
<org.drools.ruleflow.core.impl.ConnectionImpl id="10">
<type>1</type>
<from class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" reference="7"/>
<to class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" id="11">
<ruleFlowGroup>group2</ruleFlowGroup>
<id>6</id>
<name>RuleSet</name>
<incomingConnections id="12">
<org.drools.ruleflow.core.impl.ConnectionImpl reference="10"/>
</incomingConnections>
<outgoingConnections id="13">
<org.drools.ruleflow.core.impl.ConnectionImpl id="14">
<type>1</type>
<from class="org.drools.ruleflow.core.impl.RuleSetNodeImpl" reference="11"/>
<to class="org.drools.ruleflow.core.impl.EndNodeImpl" id="15">
<id>3</id>
<name>End</name>
<incomingConnections id="16">
<org.drools.ruleflow.core.impl.ConnectionImpl reference="14"/>
</incomingConnections>
<outgoingConnections id="17"/>
</to>
</org.drools.ruleflow.core.impl.ConnectionImpl>
</outgoingConnections>
</to>
</org.drools.ruleflow.core.impl.ConnectionImpl>
</outgoingConnections>
</to>
</org.drools.ruleflow.core.impl.ConnectionImpl>
</outgoingConnections>
</org.drools.ruleflow.core.impl.StartNodeImpl>
</entry>
<entry>
<long>3</long>
<org.drools.ruleflow.core.impl.EndNodeImpl reference="15"/>
</entry>
<entry>
<long>4</long>
<org.drools.ruleflow.core.impl.RuleSetNodeImpl reference="7"/>
</entry>
<entry>
<long>6</long>
<org.drools.ruleflow.core.impl.RuleSetNodeImpl reference="11"/>
</entry>
</nodes>
<variables id="18"/>
<lastNodeId>7</lastNodeId>
<id>1</id>
<name>test</name>
<version>1.0</version>
<type>RuleFlow</type>
<packageName>demo</packageName>
</org.drools.ruleflow.core.impl.RuleFlowProcessImpl>
请教这样的用法有错吗?或者正确的用法是怎么样的? |
|
|
aimer311
2008-07-01
搜了很久,都没有这方面的信息。我也是根据使用手册写的.
|

