Interface WorkflowExecution
- All Superinterfaces:
DescribableComponent
- All Known Implementing Classes:
SimpleWorkflowExecution
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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceReceives transitions of checkpoint-relevant workflow work. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCheckpointLatch(Runnable latch) Adds alatchtask to thisWorkflowExecutionrepresenting a point in time when a checkpoint can be made.voidappendTask(Consumer<WorkflowExecution> task) Appends a task for execution by the workflow control thread.appendWorkflowEvent(EventMessage event, Context parentContext) Appends a workflow-owned event from the given parent context.voidawaitStateChange(Predicate<WorkflowState> condition) Applies queued tasks until the condition is satisfied.execute(Consumer<WorkflowExecution> terminationHandler) Executes the workflow body.@Nullable Consumer<WorkflowExecution> Returns and removes the next queued task.booleanhasTasks()Indicates whether the workflow execution has queued tasks.booleanChecks whether checkpoint advancement is unsafe because workflow work is active, queued, or blocked through a barrier.voidinitializeState(WorkflowState state) Initializes this newly created execution with a workflow state.voidInterrupts the workflow driver so it can re-evaluate pending external control requests.booleanReturns whether the workflow execution runtime is running.voidonEvent(EventMessage eventMessage, ProcessingContext processingContext) Delivers an event to the workflow execution.Returns the processing context of the workflow execution.voidRegisters a listener for transitions of checkpoint-relevant work.voidrestoreAppendPosition(@Nullable ConsistencyMarker position) Restores the position from which this execution conditions its next append.state()Returns the current workflow state.voidInterrupt all running steps without producing any step/workflow cancellation events.Returns the workflow configuration.Returns the runtime operations for the current execution.Returns the workflow identifier.Returns the human-readable workflow name.Methods inherited from interface org.axonframework.common.infra.DescribableComponent
describeTo
-
Method Details
-
execute
Executes the workflow body.- Parameters:
terminationHandler- termination handler, which is executed after the execution has reached a terminalWorkflowStatus- 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
Applies queued tasks until the condition is satisfied.- Parameters:
condition- condition on the workflow state- Throws:
InterruptedException- if interrupted while waiting
-
onEvent
Delivers an event to the workflow execution.- Parameters:
eventMessage- event message to deliverprocessingContext- processing context of the delivered event
-
appendTask
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
Appends a workflow-owned event from the given parent context.- Parameters:
event- event to appendparentContext- 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
nullwhen 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:
truewhen tasks are queued
-
addCheckpointLatch
Adds alatchtask to thisWorkflowExecutionrepresenting a point in time when a checkpoint can be made.- Parameters:
latch- the latch to run when reached in thisWorkflowExecution'stask queue
-
hasUnsafeCheckpointWork
boolean hasUnsafeCheckpointWork()Checks whether checkpoint advancement is unsafe because workflow work is active, queued, or blocked through a barrier.- Returns:
trueif checkpoint advancement is unsafe,falseotherwise
-
registerCheckpointWorkStateListener
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>Cancelledevent is published. The workflow's state in the event store is left at its most recent<Step>Startedentry 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
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
Restores the position from which this execution conditions its next append.- Parameters:
position- position observed while restoring the workflow
-