Hi,
Rules are not executed as Facts are inserted into Working Memory.
Basically, think of the Working Memory as a network of connected classes
("The RETE network"). As facts are inserted into Working Memory they
enter the top of the network and propagate through it depending upon the
patterns within the left-hand-side of the rule (WHEN). Should all
pattern conditions be met an activation is queued on the agenda. When
fireAllRules is called the activations (right-hand-side; THEN) are
executed which might in turn lead to changes in the network and other
activations being created or existing removed.
So, as you insert Data objects the LHS are matched within the network
but the RHS's do not run until you call fireAllRules.
Have you tested your rules below and confirmed they provide the correct
results? I am not convinced.
With kind regards,
Mike
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of ygaurav
Sent: 02 July 2008 10:48
To: rules-users(a)lists.jboss.org
Subject: Re: [rules-users] simple rule takes long time
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
--
View this message in context:
http://www.nabble.com/simple-rule-takes-long-time-tp18192098p18233804.ht
ml
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users