By using no-loop, you are preventing the activation to increment the age
of the person to be added to the agenda. So once the process reaches
this ruleflow-group again in the next iteration of the loop, there will
be no activation for incrementing the user age anymore.
To fix this, you could:
- use an action node to increment the user age
- call update(person) after the ruleflow-group node, this will allow
the changes to the person only be taken into effect after the
ruleflow-group was deactivated, allowing reactivation of the rule for
the next loop
Kris
Quoting liuzhikun <liuzhikun(a)viewhigh.com.cn>:
I want increase user age by rule.But ruleSet node trigge only one
time.
When execute output:
new Usesr
ageA: 0
inc
ageB: 1
ageA: 1
ageB: 1
ageA: 1
ageB: 1
....
.....
rule:***************************
package t2.state
import t2.state.User;
import java.util.Map;
import java.util.HashMap;
function Map createMap(String key,Object obj){
Map m=new HashMap();
m.put(key,obj);
return m;
}
rule "boot"
dialect "mvel"
when
u : User(age==0)
then
System.out.println(" new Usesr");
kcontext.getKnowledgeRuntime().startProcess("p1rf",createMap("user",u));
end
rule "inc user age"
dialect "mvel"
ruleflow-group "inc age"
no-loop true
when
u : User();
then
System.out.println("inc");
modify(u){age+=1};
end
rule flow:************************************
<?xml version="1.0" encoding="UTF-8"?>
<process
xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process
drools-processes-5.0.xsd"
type="RuleFlow" name="p1 rule flow" id="p1rf"
package-name="t2.state" >
<header>
<imports>
<import name="t2.state.User"/>
</imports>
<variables>
<variable name="user" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="User" />
</variable>
</variables>
</header>
<nodes>
<start id="1" name="Start"/>
<join id="2" name="Restart" type="2"/>
<actionNode id="3" name="changeAge">
<action type="expression"
dialect="mvel">System.out.println("ageA:
"+user.age);</action>
</actionNode>
<ruleSet id="4" name="user rule" ruleFlowGroup="inc
age"/>
<actionNode id="5" name="changeAge">
<action type="expression"
dialect="mvel">System.out.println("ageB:
"+user.age);System.in.read();</action>
</actionNode>
<split id="6" name="decide" type="2">
<constraints>
<constraint toNodeId="2" toType="DROOLS_DEFAULT" name="go
to
rest" type="rule" priority="1"
dialect="mvel">User(age <
6)</constraint>
<constraint toNodeId="100" toType="DROOLS_DEFAULT"
name="go to
end" type="rule" priority="2"
dialect="mvel">eval(true)</constraint>
</constraints>
</split>
<end id="100" name="End"/>
</nodes>
<connections>
<connection from="1" to="2"/>
<connection from="2" to="3"/>
<connection from="3" to="4"/>
<connection from="4" to="5"/>
<connection from="5" to="6"/>
<connection from="6" to="2"/>
<connection from="6" to="100"/>
</connections>
</process>
liuzhikun
2009-10-30
Disclaimer:
http://www.kuleuven.be/cwis/email_disclaimer.htm