[rules-users] Accumulator being executed depending on the number of events

ekzl at yahoo.com ekzl at yahoo.com
Thu Jun 21 07:40:49 EDT 2012


Hi,

I'm experimenting with Drools and have troubles understanding the way
accumulators work. Before i go and look at the source code i was wondering
if the way the accumulators work is designed as described below or of it has
something to do with my rules configuration.

I'm using drools distibution 5.4.0. So this is my test case:

I have 3 similar events and 1 rule containing an accumulator. So when firing
the alerts obviously as the events are similar the same rule is fired. So
accorrding to me when the rule is fired drools creates a new accumulator and
passed data for all events but at the same time the first accumulator still
exists and receives only the datza for the second event. The 3rd event will
trigger accumulate for context1 and context2 and then create a new
accumulator with all the 3 events. This results in actually having 3
accumulators with exactly the same data.

I have created a dummy accumulator to test this:

Here is the DRL

rule "update profile"
  salience 1000 // Make sure this rule is always executed by giving it a
very high salience
  no-loop true
when
	$event: TestEvent()
	$profile: Profile( key == $event.key)
	$total : Number() from accumulate( TestEvent( $p : value, key ==
$event.key), test( $p ) )	
then
	System.out.println("Total:" + $total);
end




Here is the output

Event 1
  Context created:137
  Init called for context:137
  accumulate called for context:137 object:80
  Total called for context:137
  Total:80

Event 2
Context created:858
Init called for context:858
accumulate called for context:858 object:80
Total called for context:858
accumulate called for context:137 object:41
accumulate called for context:858 object:41
Total called for context:858
Total called for context:137
Total:121
Total:121

Event 3
Context created:724
Init called for context:724
accumulate called for context:724 object:80
accumulate called for context:724 object:41
Total called for context:724
accumulate called for context:137 object:53
accumulate called for context:858 object:53
accumulate called for context:724 object:53
Total called for context:724
Total called for context:858
Total called for context:137
Total:174
Total:174
Total:174


How can i remove the accumulator after the rule is finished?

Regards,
e

--
View this message in context: http://drools.46999.n3.nabble.com/Accumulator-being-executed-depending-on-the-number-of-events-tp4018128.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list