[rules-users] Update behavior

Burns, Barbara L (Barb) blburns at alcatel-lucent.com
Mon Mar 9 18:38:24 EDT 2009


Can someone help explain the following behavior?

Rule "rule1"
Agenda-group "apples"
No-loop
When
	Apple(color matches "red")
	Response(name1 ==null);
	$response : Response()
Then
	$response.setName1("gala");
	drools.setFocus("oranges");
End

Rule "rule2"
Agenda-group "oranges"
No-loop
When
	Orange(color matches "orange")
	Response(name2==null)
	$response:Response();
Then
	$response.setName2("sunkist");
	update($response)
	drools.setFocus("banannas");

There is 1 Apple in working memory with color matches red and 1 Orange
with color matches orange.
And there is 1 Response in working memory.
What we don't understand is that upon the update from Rule2, the
activation from rule1 refires even though $response.name1 has seemingly
been set to "gala" and should no longer match.

If the above is written as: 

Rule "rule1"
Agenda-group "apples"
No-loop
When
	Apple(color matches "red")
	$response:Response(name1 ==null);
Then
	$response.setName1("gala");
	drools.setFocus("oranges");
End

Rule "rule2"
Agenda-group "oranges"
No-loop
When
	Orange(color matches "orange")
	$response: Response(name2==null)
Then
	$response.setName2("sunkist");
	update($response)
	drools.setFocus("banannas");

Then rule1 activation is not refired.




More information about the rules-users mailing list