[rules-users] simple rule takes long time
Scott Reed
sreed at avacoda.com
Wed Jul 2 08:35:04 EDT 2008
The LHS of "Change data" is true for every initial datum so I believe
what is happening is that it sets all your isCheck flags true
immediately before the "Unique Data" rule executes. I probably wasn't
very clear about what the flag was supposed to do. I meant to suggest
using a flag to record that a duplicate was detected to prevent running
the rule on any data that is found to be a duplicate. "isDuplicate"
would probably be a better name for the flag.
All you should need is one rule like the following:
rule "Unique data"
no-loop
salience 10
when
$data1: Data( $id1: id )
$data2: Data( isCheck == false, id == $id1)
then
log.log(" data have same id (" + $data2.getId() + "):"+
$data1.getName() +" and"+
$data2.getName());
$data1.setIsCheck(); // $data1 is duplicate
update($data1);
$data.setIsCheck(); // $data is duplicate
update($data);
end
ygaurav wrote:
> Hi All
>
> I have few changes to my data class as suggested above and rule and it seems
> to work. But that brings me to another question. Here is my new data class
>
> Data class
>
> public class Data {
>
>
> private int id =0;
> public boolean isCheck = false;
> public String name = "";
> public Data(int id) {
> this.id = id;
> name = "name"+(int)(this.hashCode());
> System.out.println("id is "+id+" name is "+name);
> }
>
> public int getId() {
> return id;
> }
>
> public void setIsCheck() {
> isCheck = true;
> }
>
> public boolean getIsCheck() {
> return isCheck;
> }
>
> public String getName() {
> return name;
> }
> }
>
>
>
> rule "Unique data"
> no-loop
> salience 10
> when
> $data1: Data( $id1: id,isCheck == false)
> $data2: Data( isCheck == true, id == $id1)
> then
> log.log(" data are not unique:"+ $data1.getName() +" and
> "+$data2.getName()+ " id is "+$data2.getId()+" "+$data1.getId());
> end
>
> rule "Change data"
> no-loop
> when
> $data: Data(isCheck == false)
> then
> $data.setIsCheck();
> update($data);
> end
>
>
> So you can see from above that I set value false at the start and then set
> it to true in a different rule. Now it takes only less then a second to
> execute the rule. I was not aware of the fact that each time i insert a rule
> it start executing it.
>
> Now my question is
>
> Is it possible to stop working memory to start processing when I am
> inserting data ? So don't execute anything untill I am finished adding all
> the data and then fireAllrules
>
> thanks ( also thanks to Scott Reed-3 who led to this solution)
> Gaurav
>
>
>
>
More information about the rules-users
mailing list