Skip to content

Commit

Permalink
feat(engine): activate multi instance children in batches
Browse files Browse the repository at this point in the history
Instead of writing all the ACTIVATE commands for all children at once, we now use the
ProcessInstanceBatch.ACTIVATE command instead.

This command takes an index, which in this case is the amount of children that an ACTIVATE command will be written for.
  • Loading branch information
remcowesterhoud committed May 8, 2023
1 parent 2765304 commit bd361e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -304,6 +304,23 @@ public long activateChildInstanceWithKey(
return childInstanceKey;
}

/**
* Activate a given amount of children of a multi-instance element.
*
* @param context the context of the multi-instance element
* @param amount the amount of children for which we will write an activate command
*/
public void activateChildInstancesInBatches(final BpmnElementContext context, final int amount) {
final var record =
new ProcessInstanceBatchRecord()
.setProcessInstanceKey(context.getProcessInstanceKey())
.setBatchElementInstanceKey(context.getElementInstanceKey())
.setIndex(amount);

final var key = keyGenerator.nextKey();
commandWriter.appendFollowUpCommand(key, ProcessInstanceBatchIntent.ACTIVATE, record);
}

public void activateElementInstanceInFlowScope(
final BpmnElementContext context, final ExecutableFlowElement element) {

Expand Down
Expand Up @@ -274,7 +274,7 @@ private void activate(
if (loopCharacteristics.isSequential()) {
createInnerInstance(element, activated);
} else {
inputCollection.forEach(item -> createInnerInstance(element, activated));
stateTransitionBehavior.activateChildInstancesInBatches(context, inputCollection.size());
}
}

Expand Down

0 comments on commit bd361e6

Please sign in to comment.