tags:

views:

1322

answers:

2

When a process in jBPM forks into concurrent paths, each of these paths gets their own copy of the process variables, so that they run isolated from each other.

But what happens when the paths join again ? Obviously there could be conflicting updates. Does the context revert back to the state before the fork? Can I choose to copy individual variables from the separate tracks?

+2  A: 

I think that you have to configure the Task Controllers of your tasks. In some cases it is enough to set the access attribute in a way that does not result in conflicts (e.g. read access to the first path and read,write access to the second path). If this is not the case then you can implement your own TaskControllerHandler and implement the method void submitTaskVariables(TaskInstance taskInstance, ContextInstance contextInstance, Token token) with your custom logic. Please see: Task Controllers.

Panos
I think so that this is the correct answer. Using jBPM you write a "workflow program" and it must solve its own, unique problems,'cause no general variable sync can be perfect.
Balint Pato
+1  A: 

I tried a little experiment:

<fork name="fork1" >
 <transition to="right" />
 <transition to="left" /> 
</fork>

<node name="left">
 <event type="node-enter">
  <script>
   <expression >
    left="left";
    shared = left;
   </expression>
   <variable name='left' access='write' />
   <variable name='shared' access='write' />
  </script>
 </event>
 <transition to="join" />
</node>

<node name="right">
 <event type="node-enter">
  <script>
   <expression >
    right="right";
    token.parent.processInstance.contextInstance.setVariable("fromRight", "woot!");
    shared = right;
   </expression>
   <variable name='right' access='write' />
   <variable name='shared' access='write' />
  </script>
 </event>
 <transition to="join" />
</node>

<join name="join" >
 <transition to="done"></transition>
</join>

<end-state name="done"/>

At the end I had access to three variables, shared, right and "fromRight" which was set by the script against the parent explicitly.

The shared variable took its value from the right fork, changes made on the left seemed to dissappear.

Note that the transitions aren't actually asynchronous for me, and the whole experiment will have run in one transaction, these factors may affect the outcome

Simon Gibbs