Interface WorkflowExecution

All Superinterfaces:
DescribableComponent
All Known Implementing Classes:
SimpleWorkflowExecution

@Internal public interface WorkflowExecution extends DescribableComponent
Represents the mechanics of a workflow execution accessed by the workflow engine and its primitives.

This contract deliberately excludes workflow and step cancellation policy. Cancellation is coordinated separately so an execution remains focused on its control queue, state, event delivery, and local lifecycle.

Since:
5.4.0
Author:
Allard Buijze, Simon Zambrovski, Stefan Dragisic, Steven van Beelen
  • Method Details

    • execute

      CompletableFuture<Void> execute(Consumer<WorkflowExecution> terminationHandler)
      Executes the workflow body.
      Parameters:
      terminationHandler - termination handler, which is executed after the execution has reached a terminal WorkflowStatus
      Returns:
      a future completing when the workflow body has stopped
    • workflowExecutionOperations

      WorkflowExecutionOperations workflowExecutionOperations()
      Returns the runtime operations for the current execution.
      Returns:
      runtime operations for the current execution
    • awaitStateChange

      void awaitStateChange(Predicate<WorkflowState> condition) throws InterruptedException
      Applies queued tasks until the condition is satisfied.
      Parameters:
      condition - condition on the workflow state
      Throws:
      InterruptedException - if interrupted while waiting
    • onEvent

      void onEvent(EventMessage eventMessage, ProcessingContext processingContext)
      Delivers an event to the workflow execution.
      Parameters:
      eventMessage - event message to deliver
      processingContext - processing context of the delivered event
    • appendTask

      void appendTask(Consumer<WorkflowExecution> task)
      Appends a task for execution by the workflow control thread.
      Parameters:
      task - task to execute
    • interruptWorkflowDriver

      void interruptWorkflowDriver()
      Interrupts the workflow driver so it can re-evaluate pending external control requests.

      This is a wake-up mechanism only. It does not mutate workflow state or publish workflow events.

    • appendWorkflowEvent

      CompletableFuture<Void> appendWorkflowEvent(EventMessage event, Context parentContext)
      Appends a workflow-owned event from the given parent context.
      Parameters:
      event - event to append
      parentContext - context the append unit of work derives from
      Returns:
      a future that completes when the event has been appended
    • getNextTask

      @Nullable Consumer<WorkflowExecution> getNextTask()
      Returns and removes the next queued task.
      Returns:
      next task, or null when no task is queued
    • isRunning

      boolean isRunning()
      Returns whether the workflow execution runtime is running.
      Returns:
      true if the workflow execution runtime is running
    • hasTasks

      boolean hasTasks()
      Indicates whether the workflow execution has queued tasks.
      Returns:
      true when tasks are queued
    • addCheckpointLatch

      void addCheckpointLatch(Runnable latch)
      Adds a latch task to this WorkflowExecution representing a point in time when a checkpoint can be made.
      Parameters:
      latch - the latch to run when reached in this WorkflowExecution's task queue
    • hasUnsafeCheckpointWork

      boolean hasUnsafeCheckpointWork()
      Checks whether checkpoint advancement is unsafe because workflow work is active, queued, or blocked through a barrier.
      Returns:
      true if checkpoint advancement is unsafe, false otherwise
    • registerCheckpointWorkStateListener

      void registerCheckpointWorkStateListener(WorkflowExecution.CheckpointWorkStateListener listener)
      Registers a listener for transitions of checkpoint-relevant work.
      Parameters:
      listener - listener to notify when checkpoint work becomes safe or unsafe
    • stopForShutdown

      void stopForShutdown()
      Interrupt all running steps without producing any step/workflow cancellation events. This method is for abrupt process-level teardown (e.g. an engine shutdown lifecycle hook): it completes in-flight step futures with a non-cancellation failure so the running step is removed from bookkeeping and no <Step>Cancelled event is published. The workflow's state in the event store is left at its most recent <Step>Started entry so the step can resume on the next app start. Safe to call from any thread. Stops only in-memory execution as part of engine shutdown.

      This operation preserves the durable workflow state for replay and produces no step or workflow cancellation events. It must never be used to cancel or otherwise terminate a workflow.

    • state

      WorkflowState state()
      Returns the current workflow state.
      Returns:
      workflow state
    • initializeState

      void initializeState(WorkflowState state)
      Initializes this newly created execution with a workflow state.
      Parameters:
      state - workflow state loaded from a repository
    • processingContext

      ProcessingContext processingContext()
      Returns the processing context of the workflow execution.
      Returns:
      processing context
    • workflowName

      String workflowName()
      Returns the human-readable workflow name.
      Returns:
      returns the human-readable name of the workflow
    • workflowId

      String workflowId()
      Returns the workflow identifier.
      Returns:
      unique workflow execution identifier
    • workflowConfiguration

      WorkflowConfiguration<?> workflowConfiguration()
      Returns the workflow configuration.
      Returns:
      workflow configuration
    • restoreAppendPosition

      void restoreAppendPosition(@Nullable ConsistencyMarker position)
      Restores the position from which this execution conditions its next append.
      Parameters:
      position - position observed while restoring the workflow