Class SimpleWorkflowExecution
- All Implemented Interfaces:
WorkflowExecution,DescribableComponent
- Since:
- 5.4.0
- Author:
- Allard Buijze, Simon Zambrovski, Stefan Dragisic, Steven van Beelen
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.axoniq.framework.workflow.runtime.api.execution.context.WorkflowExecution
WorkflowExecution.CheckpointWorkStateListener -
Constructor Summary
ConstructorsConstructorDescriptionSimpleWorkflowExecution(String workflowId, Map<String, @Nullable Object> initial, ProcessingContext processingContext, WorkflowConfiguration<?> workflowConfiguration, WorkflowContext workflowContext) Constructs a new instance. -
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 eventMessage, Context parentContext) Appends a workflow-owned event from the given parent context.voidawaitStateChange(Predicate<WorkflowState> predicate) Applies queued tasks until the condition is satisfied.voiddescribeTo(ComponentDescriptor descriptor) Describe the properties ofthis DescribableComponentwith the givendescriptor.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.
-
Constructor Details
-
SimpleWorkflowExecution
public SimpleWorkflowExecution(String workflowId, Map<String, @Nullable Object> initial, ProcessingContext processingContext, WorkflowConfiguration<?> workflowConfiguration, WorkflowContext workflowContext) Constructs a new instance.- Parameters:
workflowId- workflow id.initial- initial payload of workflow instance.processingContext- processing context.workflowConfiguration- workflow configuration.workflowContext- author-facing context created by the factory
-
-
Method Details
-
execute
Executes the workflow body.The body runs inside a unit of work spanning the instance's entire lifetime. It is created from the non-transactional
WorkflowExecutionOperationsDelegation.workflowBodyUnitOfWorkFactory()so that no transactional resources are held while the instance is parked.- Specified by:
executein interfaceWorkflowExecution- Parameters:
terminationHandler- termination handler, which is executed after the execution has reached a terminalWorkflowStatus- Returns:
- a future completing when the workflow body has stopped
-
awaitStateChange
Description copied from interface:WorkflowExecutionApplies queued tasks until the condition is satisfied.- Specified by:
awaitStateChangein interfaceWorkflowExecution- Parameters:
predicate- condition on the workflow state- Throws:
InterruptedException- if interrupted while waiting
-
onEvent
Description copied from interface:WorkflowExecutionDelivers an event to the workflow execution.- Specified by:
onEventin interfaceWorkflowExecution- Parameters:
eventMessage- event message to deliverprocessingContext- processing context of the delivered event
-
stopForShutdown
public void stopForShutdown()Description copied from interface:WorkflowExecutionInterrupt 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.
- Specified by:
stopForShutdownin interfaceWorkflowExecution
-
interruptWorkflowDriver
public void interruptWorkflowDriver()Description copied from interface:WorkflowExecutionInterrupts 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.
- Specified by:
interruptWorkflowDriverin interfaceWorkflowExecution
-
addCheckpointLatch
Description copied from interface:WorkflowExecutionAdds alatchtask to thisWorkflowExecutionrepresenting a point in time when a checkpoint can be made.- Specified by:
addCheckpointLatchin interfaceWorkflowExecution- Parameters:
latch- the latch to run when reached in thisWorkflowExecution'stask queue
-
hasUnsafeCheckpointWork
public boolean hasUnsafeCheckpointWork()Description copied from interface:WorkflowExecutionChecks whether checkpoint advancement is unsafe because workflow work is active, queued, or blocked through a barrier.- Specified by:
hasUnsafeCheckpointWorkin interfaceWorkflowExecution- Returns:
trueif checkpoint advancement is unsafe,falseotherwise
-
registerCheckpointWorkStateListener
public void registerCheckpointWorkStateListener(WorkflowExecution.CheckpointWorkStateListener listener) Description copied from interface:WorkflowExecutionRegisters a listener for transitions of checkpoint-relevant work.- Specified by:
registerCheckpointWorkStateListenerin interfaceWorkflowExecution- Parameters:
listener- listener to notify when checkpoint work becomes safe or unsafe
-
getNextTask
Description copied from interface:WorkflowExecutionReturns and removes the next queued task.- Specified by:
getNextTaskin interfaceWorkflowExecution- Returns:
- next task, or
nullwhen no task is queued
-
appendTask
Description copied from interface:WorkflowExecutionAppends a task for execution by the workflow control thread.- Specified by:
appendTaskin interfaceWorkflowExecution- Parameters:
task- task to execute
-
hasTasks
public boolean hasTasks()Description copied from interface:WorkflowExecutionIndicates whether the workflow execution has queued tasks.- Specified by:
hasTasksin interfaceWorkflowExecution- Returns:
truewhen tasks are queued
-
isRunning
public boolean isRunning()Description copied from interface:WorkflowExecutionReturns whether the workflow execution runtime is running.- Specified by:
isRunningin interfaceWorkflowExecution- Returns:
- true if the workflow execution runtime is running
-
appendWorkflowEvent
public CompletableFuture<Void> appendWorkflowEvent(EventMessage eventMessage, Context parentContext) Description copied from interface:WorkflowExecutionAppends a workflow-owned event from the given parent context.- Specified by:
appendWorkflowEventin interfaceWorkflowExecution- Parameters:
eventMessage- event to appendparentContext- context the append unit of work derives from- Returns:
- a future that completes when the event has been appended
-
processingContext
Description copied from interface:WorkflowExecutionReturns the processing context of the workflow execution.- Specified by:
processingContextin interfaceWorkflowExecution- Returns:
- processing context
-
state
Description copied from interface:WorkflowExecutionReturns the current workflow state.- Specified by:
statein interfaceWorkflowExecution- Returns:
- workflow state
-
workflowExecutionOperations
Description copied from interface:WorkflowExecutionReturns the runtime operations for the current execution.- Specified by:
workflowExecutionOperationsin interfaceWorkflowExecution- Returns:
- runtime operations for the current execution
-
workflowName
Description copied from interface:WorkflowExecutionReturns the human-readable workflow name.- Specified by:
workflowNamein interfaceWorkflowExecution- Returns:
- returns the human-readable name of the workflow
-
workflowId
Description copied from interface:WorkflowExecutionReturns the workflow identifier.- Specified by:
workflowIdin interfaceWorkflowExecution- Returns:
- unique workflow execution identifier
-
workflowConfiguration
Description copied from interface:WorkflowExecutionReturns the workflow configuration.- Specified by:
workflowConfigurationin interfaceWorkflowExecution- Returns:
- workflow configuration
-
initializeState
Description copied from interface:WorkflowExecutionInitializes this newly created execution with a workflow state.- Specified by:
initializeStatein interfaceWorkflowExecution- Parameters:
state- workflow state loaded from a repository
-
restoreAppendPosition
Description copied from interface:WorkflowExecutionRestores the position from which this execution conditions its next append.- Specified by:
restoreAppendPositionin interfaceWorkflowExecution- Parameters:
position- position observed while restoring the workflow
-
workflowCancellation
-
describeTo
Description copied from interface:DescribableComponentDescribe the properties ofthis DescribableComponentwith the givendescriptor.Components should call the appropriate
describePropertymethods 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
DescribableComponentimplementation 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 thedescribeTomethod, 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:
describeToin interfaceDescribableComponent- Parameters:
descriptor- The component descriptor to describethis DescribableComponentn its properties in.
-