Skip to content

Commit

Permalink
Fix "More than one stage-level event" errors
Browse files Browse the repository at this point in the history
When two work items are completed in the same moment (in two threads),
and the following stage is to be completed automatically because of
the specified condition, two stage-level completion events are
generated.

This is something that the original design didn't expected. Here we
adapt the code to such situations. Hopefully there will be no other
consequences of such simultaneous executions.
  • Loading branch information
mederly committed Jan 24, 2019
1 parent 0550e1a commit 66a6929
Showing 1 changed file with 12 additions and 6 deletions.
Expand Up @@ -274,16 +274,22 @@ public static String getBriefDiagInfo(WfContextType wfc) {
return "pid: " + wfc.getProcessInstanceId() + ", name: " + wfc.getProcessInstanceName() + ", stage: " + wfc.getStageNumber();
}

/**
* @pre !stageEvents.isEmpty()
*/
@NotNull
public static String getCurrentStageOutcome(WfContextType wfc, List<StageCompletionEventType> stageEvents) {
if (stageEvents.size() > 1) {
throw new IllegalStateException("More than one stage-level event in " + getBriefDiagInfo(wfc) + ": " + stageEvents);
}
StageCompletionEventType event = stageEvents.get(0);
if (event.getOutcome() == null) {
Set<String> outcomes = stageEvents.stream()
.filter(e -> e.getOutcome() != null)
.map(e -> e.getOutcome())
.collect(Collectors.toSet());
if (outcomes.size() > 1) {
throw new IllegalStateException("More than one stage outcome in " + getBriefDiagInfo(wfc) + ": " + outcomes + " (" + stageEvents + ")");
} else if (outcomes.isEmpty()) {
throw new IllegalStateException("No outcome for stage-level event in " + getBriefDiagInfo(wfc));
} else {
return outcomes.iterator().next();
}
return event.getOutcome();
}

// expects normalized definition
Expand Down

0 comments on commit 66a6929

Please sign in to comment.