Hi All,
I have small doubt in the DRL file execution. I have developing the small Claims
application. I have 4 rules in my application. Below are the rules I have declared in the
drl file based on the rules.
Claims.drl
rule "Amount Validation-Rule1"
when
$c : Claims(amount >= ( maxClaimAmount) )
then
$c.setMessage ( "The total amount claimed exceeds the maximum permitted
by the
Policy" );
update($c);
end
rule "Expired Policy-Rule2"
when
$c : Claims( currentDate > ( policyExpireDate ))
then
$c.setMessage( "Your Policy has been expired" );
update($c);
end
rule "Feature Date-Rule3"
when
$c : Claims( claimDate >= ( currentDate ) )
then
$c.setMessage( "Rejecting the claim because the date on the claim is in
the future" );
update($c);
end
and my java class is
Claims.java
// Setting the values to Claims object
Claims rule = new Claims ();
rule.setAmount(amount);
rule.setClaimsHospitalStayeddays(claimsHospitalStayeddays);
rule.setClaimDate(claimDate);
rule.setCurrentDate(currentDate);
rule.setDaysPermitted(daysPermitted);
rule.setPolicyExpireDate(policyExpireDate);
rule.setCurrentDate(currentDate);
rule.setMaxClaimAmount(maxClaimAmount);
StatefulSession workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(rule);
workingMemory.fireAllRules();
If my first rule is fails then it is displaining in the messaege I managed to get that
value in my java class. If the condition is not satisfied then is fell into the infinte
loop. Again and again it is calling, not coming from that loop. If I keep the
drools.halt(); at the end of the rule then it is executing.
My question - Is there any alternate method is there to come out from infinte loop without
using drools.halt(); method? Why it is fell into the infinite loop?
Thanks,
Sarath Kumar Daruru
Show replies by date
You could simply add a "processed" flag and change your rules...
rule "Amount Validation-Rule1"
when
$c : Claims(amount >= ( maxClaimAmount), processed = false )
then
$c.setMessage ( "The total amount claimed exceeds the maximum
permitted by the Policy" );
$c.setProcessed(true);
update($c);
end
Otherwise the updates are causing the fact to be re-accessed by the RETE
network.
Alternatively you could use a ClaimOutcome object...
rule "Amount Validation-Rule1"
when
$c : Claims(amount >= ( maxClaimAmount))
not ClaimOutcome(claim = $c)
then
ClaimOutcome co = new ClaimOutcome($c, "The total amount claimed
exceeds the maximum permitted by the Policy" );
insert(co);
end
With kind regards,
Mike
________________________________
From: rules-dev-bounces(a)lists.jboss.org
[mailto:rules-dev-bounces@lists.jboss.org] On Behalf Of Sarath Kumar
Daruru
Sent: 15 January 2009 10:06
To: 'rules-dev(a)lists.jboss.org'
Subject: [rules-dev] Need to Exit from DRL without using
drools.halt()
Hi All,
I have small doubt in the DRL file execution. I have developing
the small Claims application. I have 4 rules in my application. Below
are the rules I have declared in the drl file based on the rules.
Claims.drl
rule "Amount Validation-Rule1"
when
$c : Claims(amount >= ( maxClaimAmount) )
then
$c.setMessage ( "The total amount claimed exceeds
the maximum permitted by the
Policy" );
update($c);
end
rule "Expired Policy-Rule2"
when
$c : Claims( currentDate > ( policyExpireDate ))
then
$c.setMessage( "Your Policy has been expired" );
update($c);
end
rule "Feature Date-Rule3"
when
$c : Claims( claimDate >= ( currentDate ) )
then
$c.setMessage( "Rejecting the claim because the
date on the claim is in the future" );
update($c);
end
and my java class is
Claims.java
// Setting the values to Claims object
Claims rule = new Claims ();
rule.setAmount(amount);
rule.setClaimsHospitalStayeddays(claimsHospitalStayeddays);
rule.setClaimDate(claimDate);
rule.setCurrentDate(currentDate);
rule.setDaysPermitted(daysPermitted);
rule.setPolicyExpireDate(policyExpireDate);
rule.setCurrentDate(currentDate);
rule.setMaxClaimAmount(maxClaimAmount);
StatefulSession workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(rule);
workingMemory.fireAllRules();
If my first rule is fails then it is displaining in the messaege
I managed to get that value in my java class. If the condition is not
satisfied then is fell into the infinte loop. Again and again it is
calling, not coming from that loop. If I keep the drools.halt(); at the
end of the rule then it is executing.
My question - Is there any alternate method is there to come out
from infinte loop without using drools.halt(); method? Why it is fell
into the infinite loop?
Thanks,
Sarath Kumar Daruru