[rules-users] Drools ruleflow ForEach node and RuleSet node

Kris Verlaenen kris.verlaenen at cs.kuleuven.be
Tue Oct 20 05:36:42 EDT 2009


If a for each node is executed for each parameter in the collection,
these "flows" are processed in parallel.  So when starting the process,
it starts with the first parameter and executes A1, after which it will
wait in R1 until all rules in that ruleflow-group have been executed.
The same will happen for the other parameters, resulting in A1, A1, A1,
A1.  If you then call fireAllRules(), it will execute the rules in the
ruleflow-group (R1), after which each of the flows of the for each node
will continue (resulting in A2, A2, A2, A2).

If you really want sequential behaviour, you could model this using a
loop (an XOR join followed by A1, R1, A2 followed by and XOR split that
either links back to the previous XOR join, or continues if looping
should be terminated).

Kris

Quoting "Grigoriev, Grigoriy" <Grigoriy.Grigoriev at t-systems.ru>:

> Hello,
> I have a problem with running ruleflow with ForEach node (Drools
> 5.0.1): ForEach node contains two action nodes(let's say A1 and A2)
> and one rule set node(let's say R1). I have one object, that is
> inserted into working memory (let's call it O1), and passed to
> process instance as a process variable. The collection expression in
> ForEach node contains collection of parameters. The nodes inside
> ForEach node are connected as
> A1 -> R1 -> A2 so for each parameter from the collection the
> following sequence is performed: in A1 the parameter is set to O1 via
> setter and update(O1) is called, then the rule set R1 is activated,
> where some actions are done with the object. And then, in A2, some
> data, which was changed during 'R1' stage, is extracted from object.
> The problem is that actions are not called in right consequence. For
> example, for 4 elements in the collection, the sequence, in which the
> nodes are triggered is following: A1,A1,A1,A1,R1,A2,A2,A2,A2 instead
> of  A1, R1, A2, A1, R1, A2, A1, R1, A2, A1, R1, A2
> 
> The code, used to run drools is:
> 
> Map variables = new HashMap();
>                   variables.put(OBJECT_VARIABLE_NAME, object);
>                   ksession.insert(object);
>                   ksession.startProcess(processId, variables);
>                   ksession.fireAllRules();
> 
> Can you explain such behavior?
> 
> Thank you.
>




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the rules-users mailing list