I want to control the order of firing for facts that match a single
rule. I'm using Drools 5.0.1. Is there any way to do this?
My problem can be boiled down as follows. I have an array structure
that I want to conditionally copy to a new array structure. I would
like to order of the destination array to match the source array. The
code to insert facts into working memory increments in ascending order.
It is equivalent to:
for( Object o : sourceArray )
ksess.insert( convertToMyFact( o ) );
I have constructed my rules as such:
rule "rule1"
when
$f : MyFact( prop == "testVal" )
then
copyToDestination( $f.prop, $f.index );
end
After running, however, the destination array appears in reverse order:
source[0] == destination[5]
source[1] == destination[4]
source[2] == destination[3]
source[3] == destination[2]
source[4] == destination[1]
source[5] == destination[0]
Which seems to make sense if the facts are evaluated as if they were
popped off a stack. Is there any way to force Drools to use a list
instead? Or should I just insert facts in reverse order?
I would like the order:
source[0] == destination[0]
source[1] == destination[1]
etc.
Thanks,
Dan