Class AnyMatchCombinatorDelegate

java.lang.Object
io.axoniq.framework.workflow.runtime.execution.AnyMatchCombinatorDelegate
All Implemented Interfaces:
AnyMatchCombinator

@Internal public class AnyMatchCombinatorDelegate extends Object implements AnyMatchCombinator
Default implementation of AnyMatchCombinator.
Since:
5.4.0
Author:
Stefan Dragisic
See Also:
  • Constructor Details

    • AnyMatchCombinatorDelegate

      @Internal public AnyMatchCombinatorDelegate(WorkflowExecution workflowExecution)
      Creates a new delegate backed by the given workflow state.
      Parameters:
      workflowExecution - the workflow execution.
  • Method Details

    • anyMatch

      Description copied from interface: AnyMatchCombinator
      Predicate-based combinator — resolves when the first completed result matches the given predicate. Replaces both the former race() and anySuccessful() methods:
      • anyMatch(state, WorkflowStepResult::isCompleted, ...) — any terminal wins (old race)
      • anyMatch(state, WorkflowStepResult::isSuccess, ...) — first success wins (old anySuccessful)
      • Also works with ::isFailure, ::isTimeout, ::isCanceled

      Winner selection

      The composite blocks until at least one completed result matches the predicate. That result becomes the winner and the composite delegates every state query (isSuccess(), isFailure(), result(), error(), etc.) to it.

      Fallback

      When all results complete but none matched the predicate, the first completed result (by event-sourced timestamp) becomes the consolation winner.

      Loser handling

      Losers are not automatically cancelled. The caller is responsible for cancelling remaining results if desired.

      Event-sourcing replay safety

      When multiple steps match the predicate before cancellation takes effect (e.g. during event replay), the winner is determined by event-sourced timestamps, not by array order.

      Completion

      isCompleted() is non-blocking and returns true when any completed result matches the predicate or when all results have reached a terminal state.

      Cancellation

      cancel() and cancel(reason) propagate to all results.

      Result categorization

      The returned CombinatorWorkflowStepResult provides matched() and unmatched() to access categorized sub-results. matched() returns all completed results that satisfy the predicate at the time of the call — not just the winner. Because other steps may complete between resolution and calling matched(), the list can contain more than one result. The winner (used for success()/failure()/result() delegation) is always the first element.

      For anyMatch(WorkflowStepResult::success, fastStep, slowStep) where fastStep succeeds and slowStep is still running:

      • matched() → [fastStep] — completed results that satisfied success()
      • unmatched() → [slowStep] — all other results, including those not yet completed
      Specified by:
      anyMatch in interface AnyMatchCombinator
      Parameters:
      predicate - the predicate to match against completed results.
      results - the competing step results.
      Returns:
      a composite result that resolves to the first matching result, or fallback to first completed.