Class AbstractWorkflowContext

java.lang.Object
io.axoniq.framework.workflow.runtime.execution.AbstractWorkflowContext
All Implemented Interfaces:
WorkflowContext
Direct Known Subclasses:
BaseWorkflowContext

public abstract class AbstractWorkflowContext extends Object implements WorkflowContext
Base class for author-facing WorkflowContext implementations.

Implementors extend this class and call its constructor with the workflow execution configuration. This class translates step definitions to runtime commands and delegates them to internal WorkflowExecutionOperations, which are not exposed through the author-facing context type. For reading operations, it exposes parts of the runtime state with own methods delegating to the WorkflowExecution.state().

Since:
5.4.0
Author:
Simon Zambrovski
  • Constructor Details

    • AbstractWorkflowContext

      public AbstractWorkflowContext(String workflowId, Map<String,@Nullable Object> payload, ProcessingContext processingContext, WorkflowConfiguration<?> workflowConfiguration)
      Constructs a new author-facing workflow context.
      Parameters:
      workflowId - workflow id.
      payload - initial payload.
      processingContext - processing context of the incoming event.
      workflowConfiguration - workflow configuration.
  • Method Details

    • execute

      public WorkflowStepResult execute(ExecuteStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Executes a step asynchronously from a DSL step definition.

      This method is the bridge between the DSL-facing ExecuteStepDefinition and the runtime command-mode primitive. The provided step definition is translated into the corresponding runtime command and delegated to the execution layer.

      The returned WorkflowStepResult is the durable handle for the started step. Callers may inspect the state asynchronously, wait for completion explicitly, compose it with combinators, or pass it into typed resolution methods built on top of the same handle.

      Specified by:
      execute in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing execute step definition containing step metadata, local payload, action, payload mapping, timing, and retry configuration
      Returns:
      durable asynchronous result handle for the execution step
    • awaitExecute

      public Map<String,@Nullable Object> awaitExecute(ExecuteStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Executes a step synchronously from a DSL step definition and returns the resulting step payload.

      This is the blocking counterpart of WorkflowContext.execute(ExecuteStepDefinition). It starts the step, waits until the returned WorkflowStepResult completes, propagates any execution error, and then returns the resulting payload map. If the step completes successfully without a result payload, an empty map is returned.

      Specified by:
      awaitExecute in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing execute step definition containing step metadata, local payload, action, payload mapping, timing, and retry configuration
      Returns:
      resulting payload map of the completed step, or an empty map when no result payload is produced
    • waitForEvent

      public WorkflowStepResult waitForEvent(WaitForStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Starts an asynchronous wait step from a DSL step definition.

      This method translates the provided WaitForStepDefinition into the runtime wait command and delegates it to the execution layer. The returned WorkflowStepResult completes when a matching event is received or the configured timeout expires.

      Specified by:
      waitForEvent in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing wait step definition containing step metadata, event condition, payload mapping, and timing
      Returns:
      durable asynchronous result handle representing the active wait step
    • awaitEvent

      public Map<String,@Nullable Object> awaitEvent(WaitForStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Starts a wait step from a DSL step definition and blocks until it completes.

      This is the blocking counterpart of WorkflowContext.waitForEvent(WaitForStepDefinition). The method waits until the step completes, propagates any failure from the underlying WorkflowStepResult, and returns the resulting payload map. If the completed wait step has no result payload, an empty map is returned.

      Specified by:
      awaitEvent in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing wait step definition containing step metadata, event condition, payload mapping, and timing
      Returns:
      resulting payload map of the completed wait step, or an empty map when no result payload is produced
    • modifyPayload

      public WorkflowStepResult modifyPayload(PayloadStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Applies a payload modification asynchronously from a DSL step definition.

      This method bridges PayloadStepDefinition to the runtime payload modification primitive. The returned WorkflowStepResult represents the durable completion handle for the modification step.

      Specified by:
      modifyPayload in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing payload step definition containing step metadata and payload modification
      Returns:
      durable asynchronous result handle for the payload modification step
    • awaitModifyPayload

      public void awaitModifyPayload(PayloadStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Applies a payload modification from a DSL step definition and blocks until it completes.

      This is the blocking counterpart of WorkflowContext.modifyPayload(PayloadStepDefinition). The method waits for the returned WorkflowStepResult to complete and propagates any failure from the underlying step.

      Specified by:
      awaitModifyPayload in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing payload step definition containing step metadata and payload modification
    • publish

      public WorkflowStepResult publish(PublishStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Publishes a business event as a durable workflow step from a DSL step definition.

      This method bridges PublishStepDefinition to the runtime publish primitive. Exactly one event is appended: the definition's event enriched with workflow metadata, acting as both the business event and the replay-safe checkpoint of the step. The returned WorkflowStepResult represents the durable completion handle for the publish step.

      Specified by:
      publish in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing publish step definition containing step metadata and the event to publish
      Returns:
      durable asynchronous result handle for the publish step
    • awaitPublish

      public void awaitPublish(PublishStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Publishes a business event from a DSL step definition and blocks until the step is recorded.

      This is the blocking counterpart of WorkflowContext.publish(PublishStepDefinition). The method waits for the returned WorkflowStepResult to complete and propagates any failure from the underlying step.

      Specified by:
      awaitPublish in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing publish step definition containing step metadata and the event to publish
    • migrateVersion

      public boolean migrateVersion(VersionStepDefinition stepDefinition)
      Description copied from interface: WorkflowContext
      Migrates the workflow to the version carried by stepDefinition for the given changeId and returns whether the new branch is in effect for this workflow:
      • Migration step already recorded → returns true iff the recorded version is >= the requested version.
      • No step recorded yet, workflow already at the requested version → returns true without publishing a redundant step.
      • No step recorded yet, requested version strictly greater than current → publishes the migration step and returns true; if the replay-drift guard fires (in-flight workflow already ran past this point), returns false and emits nothing.
      • Downgrade attempt (requested < current, no step recorded) → throws IllegalArgumentException.
      Specified by:
      migrateVersion in interface WorkflowContext
      Parameters:
      stepDefinition - author-facing version step definition.
      Returns:
      true iff the workflow has committed to (or is past) the requested version for this changeId; false if it stays on the legacy branch.
    • fail

      public void fail(FailWorkflowDefinition definition)
      Description copied from interface: WorkflowContext
      Terminates the workflow with failure from a DSL step definition.

      The provided FailWorkflowDefinition is translated into the runtime termination command and delegated to the execution layer.

      Specified by:
      fail in interface WorkflowContext
      Parameters:
      definition - author-facing failure definition containing step metadata and failure cause
    • cancel

      public void cancel(CancelWorkflowDefinition definition)
      Description copied from interface: WorkflowContext
      Terminates the workflow with cancellation from a DSL definition.

      The provided CancelWorkflowDefinition is translated into the runtime termination command and delegated to the execution layer.

      Specified by:
      cancel in interface WorkflowContext
      Parameters:
      definition - author-facing cancellation definition containing step metadata and optional cause
    • cancelStep

      public void cancelStep(CancelStepDefinition definition)
      Description copied from interface: WorkflowContext
      Terminates the step with cancellation from a DSL definition.

      The provided CancelStepDefinition is translated into the runtime termination command and delegated to the execution layer.

      Specified by:
      cancelStep in interface WorkflowContext
      Parameters:
      definition - author-facing cancellation definition containing step metadata and optional cause
    • allMatch

      Description copied from interface: WorkflowContext
      Returns a result that completes successfully when every supplied result matches the predicate.
      Specified by:
      allMatch in interface WorkflowContext
      Parameters:
      predicate - condition each result must satisfy
      results - results to combine
      Returns:
      combined result
    • anyMatch

      Description copied from interface: WorkflowContext
      Returns a result that completes successfully when any supplied result matches the predicate.
      Specified by:
      anyMatch in interface WorkflowContext
      Parameters:
      predicate - condition a result must satisfy
      results - results to combine
      Returns:
      combined result
    • noneMatch

      Description copied from interface: WorkflowContext
      Returns a result that completes successfully when no supplied result matches the predicate.
      Specified by:
      noneMatch in interface WorkflowContext
      Parameters:
      predicate - condition no result may satisfy
      results - results to combine
      Returns:
      combined result
    • resolveComponent

      public <T> T resolveComponent(Class<T> componentType)
      Description copied from interface: WorkflowContext
      Resolves a component from the processing context of this workflow invocation.
      Specified by:
      resolveComponent in interface WorkflowContext
      Type Parameters:
      T - type of component to resolve
      Parameters:
      componentType - type of component to resolve
      Returns:
      the resolved component
    • workflowId

      public String workflowId()
      Description copied from interface: WorkflowContext
      Returns the unique workflow execution identifier.
      Specified by:
      workflowId in interface WorkflowContext
      Returns:
      workflow identifier
    • workflowDefinitionId

      public VersionedType workflowDefinitionId()
      Description copied from interface: WorkflowContext
      Returns the workflow definition identity, including its current definition version.

      Use VersionedType.version() to obtain the definition version.

      Specified by:
      workflowDefinitionId in interface WorkflowContext
      Returns:
      workflow definition identity
    • workflowPayload

      public Map<String,@Nullable Object> workflowPayload()
      Description copied from interface: WorkflowContext
      Returns the current workflow payload.
      Specified by:
      workflowPayload in interface WorkflowContext
      Returns:
      the workflow payload
    • workflowStatus

      public WorkflowStatus workflowStatus()
      Description copied from interface: WorkflowContext
      Returns the status of the workflow execution.
      Specified by:
      workflowStatus in interface WorkflowContext
      Returns:
      workflow status
    • workflowStepNames

      public List<String> workflowStepNames()
      Description copied from interface: WorkflowContext
      Retrieves a list of step names in the workflow execution.
      Specified by:
      workflowStepNames in interface WorkflowContext
      Returns:
      list of step names
    • getStep

      public @Nullable WorkflowStep getStep(String stepName)
      Description copied from interface: WorkflowContext
      Retrieves a step by name.
      Specified by:
      getStep in interface WorkflowContext
      Parameters:
      stepName - name of the step
      Returns:
      workflow step
    • containsStep

      public boolean containsStep(String stepName)
      Description copied from interface: WorkflowContext
      Checks if a step with the given name exists in the workflow execution.
      Specified by:
      containsStep in interface WorkflowContext
      Parameters:
      stepName - name of the step
      Returns:
      true if the step exists, false otherwise
    • processingContext

      protected ProcessingContext processingContext()
      Internal access to processing context used by implemeters.
      Returns:
      processing context.