Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge variables from parallel flows in Activiti?

Currently I have a sub-process which uses fork/join mechanism to create parallel flows. Lest assume that there are two flows: A, B. Each of that flows takes as input variables complex object CONTEXT. Also each of that flows make some calculation and updates CONTEXT inside. As a output each of flows return updated CONTEXT. The problem here is that in Join point, last result of CONTEXT overrides previous one. Lets assume that flow A fill be finished first with result CONTEXT_1 and flow B will return CONTEXT_2. So final result will be CONTEXT_2 and all changes from flow A will be lost.

The question here is - how to merge results from two flows? enter image description here

UPDATE: From my observations passed variable (CONTEXT) from SuperProcess to SubProcess are copied(CONTEXT') and after subProcess is finished, new value of passed variable(CONTEXT') will take place of original (CONTEXT).

In the example below I mean that all passed variables have the same name.

Example:

  1. SuperProcess P1 (Variable: CONTEXT) calls SubProcess P2(variables are passed by copy);
  2. SubProcess P2 (Variable: CONTEXT') creates two parallel flows(Tasks) A, B(variables are passed by copy);

  3. A Task (Variable: CONTEXT_1) updates value of variable, finishes execution and returns variable;

    3.1. CONTEXT_1 takes place of variable CONTEXT' so P2 can see only this new value as names of this variables the same;

  4. Meanwhile B Task (Variable: CONTEXT_2) is still working and after some time updates variable, finishes execution and returns variable;

    4.1. CONTEXT_2 takes place of variable CONTEXT_1 so P2 can see only this new value as names of this variables the same;

  5. SubProcess P2 (Variable: CONTEXT_2) finish the execution and returns new veriable to SuperProcess. Result -> CONTEXT_1 is lossed.

My aim scenario:

  1. SuperProcess P1 (Variable: CONTEXT) calls SubProcess P2(variables are passed by copy);
  2. SubProcess P2 (Variable: CONTEXT') creates two parallel flows(Tasks) A, B(variables are passed by copy);

  3. A Task (Variable: CONTEXT_1) updates value of variable, finishes execution and returns variable;

    3.1. CONTEXT_1 and CONTEXT are merged into CONTEXT_M1, in other words, only new changes of CONTEXT_1 will be applied to CONTEXT.

  4. Meanwhile B Task (Variable: CONTEXT_2) is still working and after some time updates variable, finishes execution and returns variable;

    4.1. CONTEXT_2 and CONTEXT_M1 are merged into CONTEXT_M2, in other words, only new changes of CONTEXT_2 will be applied to CONTEXT_M1 so previous update will be not lost;

  5. SubProcess P2 (Variable: CONTEXT_M2) finish the execution and returns new veriable to SuperProcess. Result -> CONTEXT_M2. All changes are saved.
like image 724
Speise Avatar asked Jul 31 '17 18:07

Speise


2 Answers

After couple days of investigation we figured out that copying variables from SuperProcess to SubProcess is default behavior (link):

"You can pass process variables to the sub process and vice versa. The data is copied into the subprocess when it is started and copied back into the main process when it ends."

As the decision we pass variables into SubProcess under different name and merge with source variable after SubProcess finish: enter image description here

like image 65
Speise Avatar answered Nov 18 '22 16:11

Speise


When you say merge? What do you mean exactly? What is your desired behavior at the emerge point?

If you want to maintain both contexts then use a map with the execution ID as the key, however, I doubt that is what you want.

Greg

like image 1
Greg Harley Avatar answered Nov 18 '22 14:11

Greg Harley