[rules-users] Recursion problem due to modify an object.

KAPX Kapil.Kumar at GlobalLogic.com
Wed Feb 21 04:18:07 EST 2007


Hi,

I am explaining the scenerio of recursion problem which I am facing. I have
three rules in a ruleset. 

rule "gst_rate_ol"
		no-loop true
		salience 50
		when
			QuoteUpdater:QuoteUpdater()
			eval(QuoteUpdater.getCustomerTypeCountry().equals("New Zealand") &&
			 QuoteUpdater.isFinanceLease() == true ||
			 QuoteUpdater.isRental() == true ||
			 QuoteUpdater.isOperatingLease() == true ||
			 QuoteUpdater.isHirePurchase() == true)
		then
			System.out.println("1");
			TEMP = BigDecimal . valueOf ( 0.125 ) ;
			QuoteUpdater . setQuoteLevelGSTRate ( BigDecimal . valueOf ( TEMP .
doubleValue ( ) ) ) ;
			modify(QuoteUpdater);
end
rule "NZ_SD"
		no-loop true
		salience 45
		when
			QuoteUpdater:QuoteUpdater()
			eval(QuoteUpdater . getCustomerTypeCountry (  ).equals("New Zealand"))
		then
			System.out.println("2");
			QuoteUpdater . setQuoteLevelGSTStreamRate ( BigDecimal . valueOf ( 0 ) )
;
			QuoteUpdater . setQuoteLevelStampDutyRate ( BigDecimal . valueOf ( 0 ) )
;
			GL_SD_Amt = BigDecimal . valueOf ( 0 ) ;
			QuoteUpdater . setQuoteLevelStampDutyAmount ( BigDecimal . valueOf ( 0 )
) ;
			modify(QuoteUpdater);
end
rule "gst_stream_rate_ol"
		salience 40
		no-loop true
		when
			QuoteUpdater:QuoteUpdater()
			eval(QuoteUpdater.getCustomerTypeCountry().equals("New Zealand") &&
			 QuoteUpdater.isRental() == true ||
			 QuoteUpdater.isOperatingLease() == true)
		then
 			System.out.println("3");
			TEMP = BigDecimal . valueOf ( 0.125 ) ;
			QuoteUpdater . setQuoteLevelGSTStreamRate ( BigDecimal . valueOf ( TEMP .
doubleValue ( ) ) ) ;
			modify(QuoteUpdater);
end

while executing this ruleset a problem of recursion is occouring due to
modify statement. To resolve this problem I have made some changes in drools
code. I am explaining about the changes which I have made. some changes in
following functions.

Class: DefaultAgenda
    public boolean fireNextItem(final AgendaFilter filter) throws
ConsequenceException {
        final AgendaGroupImpl group = (AgendaGroupImpl) getNextFocus();
        // return if there are no Activations to fire
        if ( group == null ) {return false;}
        final AgendaItem item = (AgendaItem) group.getNext();
        if ( item == null ) {return false;}
           item.getRule().setFired(true);
        if ( filter == null || filter.accept( item ) ) {fireActivation( item
);}
        return true;
    }

Class: TerminalNode

    public void assertTuple(final ReteTuple tuple,final PropagationContext
context,final ReteooWorkingMemory         workingMemory,final boolean
fireActivationCreated) {
        // if the current Rule is no-loop and the origin rule is the same
then
        // return
         if ( this.rule.getNoLoop() && this.rule.equals(
context.getRuleOrigin() ) ) {return;}
             if(this.rule.isFired()) return;        
        final InternalAgenda agenda = (InternalAgenda)
workingMemory.getAgenda();

Class: Rule
    one attribute added name fired. (type boolean).

By making these changes i am able to execute a rule single time only even
whether there is any modify statement in rule.

Please give your suggestion and feedback on this approach or avioding the
recusrion problem.
Thanks in advance.
Kapil



-- 
View this message in context: http://www.nabble.com/Recursion-problem-due-to-modify-an-object.-tf3265585.html#a9077586
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list