[rules-dev] Need to Exit from DRL without using drools.halt()

surya_n2007 surya_n2007 at yahoo.co.in
Wed Mar 11 19:53:03 EDT 2009


Hi All,

    Once you add statement update,drools assumes need to recheck all rules
to overcome this use attribute lock-on-active true. By using the above
attribute we are informing not to execute the rules
again.

        rule "Amount Validation-Rule1" lock-on-active true
        when
             $c : Claims(amount >= ( maxClaimAmount) )
        then
             $c.setMessage ( "The total amount claimed exceeds the maximum
permitted by the
                                                                Policy" );
              update($c);
end

If you need to just add message to the object or error code  use
insertLogical($c)  instead of update ,it wont execute all rules again.

Thanks & Regards
Surya.



Daruru wrote:
> 
> 
> 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
> 
> 
> 
> 
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
> 
> 

-- 
View this message in context: http://www.nabble.com/Need-to-Exit-from-DRL-without-using-drools.halt%28%29-tp21474695p22234722.html
Sent from the drools - dev mailing list archive at Nabble.com.




More information about the rules-dev mailing list