[rules-users] Executing more than one rules having no infinite execution

Hushen Savani hushen.savani at elitecore.com
Fri Dec 7 02:59:56 EST 2012


Hi,

 

                I have a simple rule as following:

 

import java.util.HashMap;

 

rule "first"

when

     a : CrestelRuleModel( $hmap : singleHashMap!=null);

then

     System.out.println("Old Map: " + $hmap);

     HashMap mapp = new HashMap();

     mapp.put("hello", "world");

     a.setSingleHashMap(mapp);

     System.out.println("New Map: " + a.getSingleHashMap());

     update(a);

end;

 

When I invoke the rule from my client, the rule is executed infinitely.

 

So, I have placed a "drools.halt()" before "end" statement of above rule.
So, it stopped executing infinitely as I wanted. But is it a good practice?

 

Now, I want my input to be filtered by two rules, so I have placed rules
like following:

 

import java.util.HashMap;

 

rule "first"

when

     a : CrestelRuleModel( $hmap : singleHashMap!=null);

then

     System.out.println("Old Map: " + $hmap);

     HashMap mapp = new HashMap();

     mapp.put("hello", "world");

     a.setSingleHashMap(mapp);

     System.out.println("New Map: " + a.getSingleHashMap());

     update(a);

     drools.halt();

end;

 

rule "second"

when

     b : CrestelRuleModel( $hmap2 : singleHashMap!=null);

then

     System.out.println("Old Map2: " + $hmap2);

     HashMap mapp2 = new HashMap();

     mapp2.put("hello2", "world2");

     b.setSingleHashMap(mapp2);

     System.out.println("New Map2: " + b.getSingleHashMap());

     update(b);

     drools.halt();

end;

 

But in above case, only the "second"  rule executes. What to do in order to
execute both the rules without any infinite loop?

 

Kindly share some pointers on this. Thanks.

 

 

PS: CrestelRuleModel is my POJO model having following fields,

 

public class CrestelRuleModel {

       

       private ArrayList arrayListOfHashMap;

       private HashMap singleHashMap;

       private Object object;

       private String remarks;

 

       //Getters and Setters

 

}

 

Best Regards

Hushen Savani | Crestel Billing

ecTag

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20121207/4c58b4c5/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 2753 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/rules-users/attachments/20121207/4c58b4c5/attachment-0001.png 


More information about the rules-users mailing list