Class EventSourcedWorkflowState

java.lang.Object
io.axoniq.framework.workflow.runtime.execution.EventSourcedWorkflowState
All Implemented Interfaces:
WorkflowState, DescribableComponent

@Internal public class EventSourcedWorkflowState extends Object implements WorkflowState
Holds the current state of a workflow and modified by the evolve(org.axonframework.messaging.eventhandling.EventMessage, org.axonframework.messaging.core.unitofwork.ProcessingContext) method receiving messages.
Since:
5.4.0
Author:
Simon Zambrovski
  • Field Details

    • PAYLOAD_TYPE

      public static final TypeReference<Map<String,@Nullable Object>> PAYLOAD_TYPE
      Type reference for a map of strings to objects used as workflow payload.
  • Constructor Details

    • EventSourcedWorkflowState

      @Internal public EventSourcedWorkflowState(String workflowId, VersionedType workflowDefinition)
      Creates a new workflow state without reference to a workflow context and with an empty initial payload.
      Parameters:
      workflowId - workflow id of the workflow execution
      workflowDefinition - workflow definition representing the reference to the definition (name and version)
    • EventSourcedWorkflowState

      @Internal public EventSourcedWorkflowState(String workflowId, Map<String,@Nullable Object> payload, VersionedType workflowDefinition)
      Creates a new workflow state without reference to a workflow context.
      Parameters:
      workflowId - workflow id of the workflow execution
      payload - initial workflow payload
      workflowDefinition - workflow definition representing the reference to the definition (name and version)
  • Method Details

    • requireEventSourcedState

      public static EventSourcedWorkflowState requireEventSourcedState(WorkflowState state)
      Returns the event sourced workflow state.
      Parameters:
      state - workflow state
      Returns:
      event sourced workflow state or throws an exception if the given state is not an event sourced state
      Throws:
      IllegalArgumentException - if the given state is not an event sourced state
    • criteriaBuilder

      public static EventCriteria criteriaBuilder(String workflowId)
      Criteria selecting all workflow-owned events for a single workflow identifier.
      Parameters:
      workflowId - workflow identifier
      Returns:
      event criteria for workflow-state reconstruction
    • workflowId

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

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

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

      public String versionFor(String changeId)
      Description copied from interface: WorkflowState
      Returns the effective version for the given changeId.

      The effective version is the recorded version-migration string when a migration step has been projected for the change. Otherwise, it is WorkflowState.workflowDefinitionId()'s version. This fallback is implicit, so workflows that have never executed a ctx.migrateVersion(changeId, newVersion) call carry no version-migration step in their event history.

      Specified by:
      versionFor in interface WorkflowState
      Parameters:
      changeId - the change identifier to query
      Returns:
      effective version for the change
    • hasVersionMigrationStep

      public boolean hasVersionMigrationStep(String changeId)
      Description copied from interface: WorkflowState
      Returns true iff a migration step has been projected into state for the given changeId.

      Used by the migration primitive to distinguish "no recorded step, using the definition identity's version" from "an explicit migration step at the effective version". Only the former permits a new step to be written for a different version number.

      Specified by:
      hasVersionMigrationStep in interface WorkflowState
      Parameters:
      changeId - the change identifier to query
      Returns:
      true iff a migration step was recorded for this changeId
    • versionMigrations

      public Map<String,String> versionMigrations()
      Description copied from interface: WorkflowState
      Returns the recorded version migrations by change identifier.
      Specified by:
      versionMigrations in interface WorkflowState
      Returns:
      immutable map of recorded version migrations
    • workflowDefinitionId

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

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

      Specified by:
      workflowDefinitionId in interface WorkflowState
      Returns:
      workflow definition identity
    • workflowStatus

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

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

      public Map<String,@Nullable Object> payload()
      Description copied from interface: WorkflowState
      Retrieves the payload of the workflow execution.
      Specified by:
      payload in interface WorkflowState
      Returns:
      payload of the workflow execution
    • evolve

      public WorkflowState evolve(EventMessage eventMessage, ProcessingContext processingContext)
      Applies an event while notifying workflow status listeners.
      Parameters:
      eventMessage - event message applied to the workflow state
      processingContext - context in which the event is applied
      Returns:
      this evolved workflow state
    • throwTerminalCause

      public void throwTerminalCause()
      Description copied from interface: WorkflowState
      Guards against invoking any primitive when the workflow has already reached a terminal state. Rethrows the original termination cause wrapped in the appropriate exception type.
      Specified by:
      throwTerminalCause in interface WorkflowState
    • describeTo

      public void describeTo(ComponentDescriptor descriptor)
      Description copied from interface: DescribableComponent
      Describe the properties of this DescribableComponent with the given descriptor.

      Components should call the appropriate describeProperty methods on the descriptor to register their properties. The descriptor is responsible for determining how these properties are formatted and structured in the final output.

      Best Practices: As a general rule, all relevant fields of a DescribableComponent implementation should be described in this method. However, developers have discretion to include only the fields that make sense in the context. Not every field may be meaningful for description purposes, especially internal implementation details. Furthermore, components might want to expose different information based on their current state. The final decision on what properties to include lies with the person implementing the describeTo method, who should focus on providing information that is useful for understanding the component's configuration and state.

      Example implementation:

       public void describeTo(ComponentDescriptor descriptor) {
           descriptor.describeProperty("name", this.name);
           descriptor.describeProperty("enabled", this.enabled);
           descriptor.describeProperty("configuration", this.configuration); // A nested component
           descriptor.describeProperty("handlers", this.eventHandlers);      // A collection
       }
       
      Specified by:
      describeTo in interface DescribableComponent
      Parameters:
      descriptor - The component descriptor to describe this DescribableComponentn its properties in.
    • toString

      public String toString()
      Overrides:
      toString in class Object