Class AbstractWorkflowContext
- All Implemented Interfaces:
WorkflowContext
- Direct Known Subclasses:
BaseWorkflowContext
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 Summary
ConstructorsConstructorDescriptionAbstractWorkflowContext(String workflowId, Map<String, @Nullable Object> payload, ProcessingContext processingContext, WorkflowConfiguration<?> workflowConfiguration) Constructs a new author-facing workflow context. -
Method Summary
Modifier and TypeMethodDescriptionallMatch(Predicate<WorkflowStepResult> predicate, WorkflowStepResult... results) Returns a result that completes successfully when every supplied result matches the predicate.anyMatch(Predicate<WorkflowStepResult> predicate, WorkflowStepResult... results) Returns a result that completes successfully when any supplied result matches the predicate.awaitEvent(WaitForStepDefinition stepDefinition) Starts a wait step from a DSL step definition and blocks until it completes.awaitExecute(ExecuteStepDefinition stepDefinition) Executes a step synchronously from a DSL step definition and returns the resulting step payload.voidawaitModifyPayload(PayloadStepDefinition stepDefinition) Applies a payload modification from a DSL step definition and blocks until it completes.voidawaitPublish(PublishStepDefinition stepDefinition) Publishes a business event from a DSL step definition and blocks until the step is recorded.voidcancel(CancelWorkflowDefinition definition) Terminates the workflow with cancellation from a DSL definition.voidcancelStep(CancelStepDefinition definition) Terminates the step with cancellation from a DSL definition.booleancontainsStep(String stepName) Checks if a step with the given name exists in the workflow execution.execute(ExecuteStepDefinition stepDefinition) Executes a step asynchronously from a DSL step definition.voidfail(FailWorkflowDefinition definition) Terminates the workflow with failure from a DSL step definition.@Nullable WorkflowStepRetrieves a step by name.booleanmigrateVersion(VersionStepDefinition stepDefinition) Migrates the workflow to the version carried bystepDefinitionfor the given changeId and returns whether the new branch is in effect for this workflow: Migration step already recorded → returnstrueiff the recorded version is>=the requested version. No step recorded yet, workflow already at the requested version → returnstruewithout publishing a redundant step. No step recorded yet, requested version strictly greater than current → publishes the migration step and returnstrue; if the replay-drift guard fires (in-flight workflow already ran past this point), returnsfalseand emits nothing. Downgrade attempt (requested<current, no step recorded) → throwsIllegalArgumentException.modifyPayload(PayloadStepDefinition stepDefinition) Applies a payload modification asynchronously from a DSL step definition.noneMatch(Predicate<WorkflowStepResult> predicate, WorkflowStepResult... results) Returns a result that completes successfully when no supplied result matches the predicate.protected ProcessingContextInternal access to processing context used by implemeters.publish(PublishStepDefinition stepDefinition) Publishes a business event as a durable workflow step from a DSL step definition.<T> TresolveComponent(Class<T> componentType) Resolves a component from the processing context of this workflow invocation.waitForEvent(WaitForStepDefinition stepDefinition) Starts an asynchronous wait step from a DSL step definition.Returns the workflow definition identity, including its current definition version.Returns the unique workflow execution identifier.Returns the current workflow payload.Returns the status of the workflow execution.Retrieves a list of step names in the workflow execution.
-
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
Description copied from interface:WorkflowContextExecutes a step asynchronously from a DSL step definition.This method is the bridge between the DSL-facing
ExecuteStepDefinitionand the runtime command-mode primitive. The provided step definition is translated into the corresponding runtime command and delegated to the execution layer.The returned
WorkflowStepResultis 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:
executein interfaceWorkflowContext- 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
Description copied from interface:WorkflowContextExecutes 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 returnedWorkflowStepResultcompletes, 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:
awaitExecutein interfaceWorkflowContext- 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
Description copied from interface:WorkflowContextStarts an asynchronous wait step from a DSL step definition.This method translates the provided
WaitForStepDefinitioninto the runtime wait command and delegates it to the execution layer. The returnedWorkflowStepResultcompletes when a matching event is received or the configured timeout expires.- Specified by:
waitForEventin interfaceWorkflowContext- 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
Description copied from interface:WorkflowContextStarts 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 underlyingWorkflowStepResult, and returns the resulting payload map. If the completed wait step has no result payload, an empty map is returned.- Specified by:
awaitEventin interfaceWorkflowContext- 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
Description copied from interface:WorkflowContextApplies a payload modification asynchronously from a DSL step definition.This method bridges
PayloadStepDefinitionto the runtime payload modification primitive. The returnedWorkflowStepResultrepresents the durable completion handle for the modification step.- Specified by:
modifyPayloadin interfaceWorkflowContext- Parameters:
stepDefinition- author-facing payload step definition containing step metadata and payload modification- Returns:
- durable asynchronous result handle for the payload modification step
-
awaitModifyPayload
Description copied from interface:WorkflowContextApplies 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 returnedWorkflowStepResultto complete and propagates any failure from the underlying step.- Specified by:
awaitModifyPayloadin interfaceWorkflowContext- Parameters:
stepDefinition- author-facing payload step definition containing step metadata and payload modification
-
publish
Description copied from interface:WorkflowContextPublishes a business event as a durable workflow step from a DSL step definition.This method bridges
PublishStepDefinitionto 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 returnedWorkflowStepResultrepresents the durable completion handle for the publish step.- Specified by:
publishin interfaceWorkflowContext- 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
Description copied from interface:WorkflowContextPublishes 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 returnedWorkflowStepResultto complete and propagates any failure from the underlying step.- Specified by:
awaitPublishin interfaceWorkflowContext- Parameters:
stepDefinition- author-facing publish step definition containing step metadata and the event to publish
-
migrateVersion
Description copied from interface:WorkflowContextMigrates the workflow to the version carried bystepDefinitionfor the given changeId and returns whether the new branch is in effect for this workflow:- Migration step already recorded → returns
trueiff the recorded version is>=the requested version. - No step recorded yet, workflow already at the requested version → returns
truewithout 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), returnsfalseand emits nothing. - Downgrade attempt (requested
<current, no step recorded) → throwsIllegalArgumentException.
- Specified by:
migrateVersionin interfaceWorkflowContext- Parameters:
stepDefinition- author-facing version step definition.- Returns:
trueiff the workflow has committed to (or is past) the requested version for thischangeId;falseif it stays on the legacy branch.
- Migration step already recorded → returns
-
fail
Description copied from interface:WorkflowContextTerminates the workflow with failure from a DSL step definition.The provided
FailWorkflowDefinitionis translated into the runtime termination command and delegated to the execution layer.- Specified by:
failin interfaceWorkflowContext- Parameters:
definition- author-facing failure definition containing step metadata and failure cause
-
cancel
Description copied from interface:WorkflowContextTerminates the workflow with cancellation from a DSL definition.The provided
CancelWorkflowDefinitionis translated into the runtime termination command and delegated to the execution layer.- Specified by:
cancelin interfaceWorkflowContext- Parameters:
definition- author-facing cancellation definition containing step metadata and optional cause
-
cancelStep
Description copied from interface:WorkflowContextTerminates the step with cancellation from a DSL definition.The provided
CancelStepDefinitionis translated into the runtime termination command and delegated to the execution layer.- Specified by:
cancelStepin interfaceWorkflowContext- Parameters:
definition- author-facing cancellation definition containing step metadata and optional cause
-
allMatch
public CombinatorWorkflowStepResult allMatch(Predicate<WorkflowStepResult> predicate, WorkflowStepResult... results) Description copied from interface:WorkflowContextReturns a result that completes successfully when every supplied result matches the predicate.- Specified by:
allMatchin interfaceWorkflowContext- Parameters:
predicate- condition each result must satisfyresults- results to combine- Returns:
- combined result
-
anyMatch
public CombinatorWorkflowStepResult anyMatch(Predicate<WorkflowStepResult> predicate, WorkflowStepResult... results) Description copied from interface:WorkflowContextReturns a result that completes successfully when any supplied result matches the predicate.- Specified by:
anyMatchin interfaceWorkflowContext- Parameters:
predicate- condition a result must satisfyresults- results to combine- Returns:
- combined result
-
noneMatch
public CombinatorWorkflowStepResult noneMatch(Predicate<WorkflowStepResult> predicate, WorkflowStepResult... results) Description copied from interface:WorkflowContextReturns a result that completes successfully when no supplied result matches the predicate.- Specified by:
noneMatchin interfaceWorkflowContext- Parameters:
predicate- condition no result may satisfyresults- results to combine- Returns:
- combined result
-
resolveComponent
Description copied from interface:WorkflowContextResolves a component from the processing context of this workflow invocation.- Specified by:
resolveComponentin interfaceWorkflowContext- Type Parameters:
T- type of component to resolve- Parameters:
componentType- type of component to resolve- Returns:
- the resolved component
-
workflowId
Description copied from interface:WorkflowContextReturns the unique workflow execution identifier.- Specified by:
workflowIdin interfaceWorkflowContext- Returns:
- workflow identifier
-
workflowDefinitionId
Description copied from interface:WorkflowContextReturns the workflow definition identity, including its current definition version.Use
VersionedType.version()to obtain the definition version.- Specified by:
workflowDefinitionIdin interfaceWorkflowContext- Returns:
- workflow definition identity
-
workflowPayload
Description copied from interface:WorkflowContextReturns the current workflow payload.- Specified by:
workflowPayloadin interfaceWorkflowContext- Returns:
- the workflow payload
-
workflowStatus
Description copied from interface:WorkflowContextReturns the status of the workflow execution.- Specified by:
workflowStatusin interfaceWorkflowContext- Returns:
- workflow status
-
workflowStepNames
Description copied from interface:WorkflowContextRetrieves a list of step names in the workflow execution.- Specified by:
workflowStepNamesin interfaceWorkflowContext- Returns:
- list of step names
-
getStep
Description copied from interface:WorkflowContextRetrieves a step by name.- Specified by:
getStepin interfaceWorkflowContext- Parameters:
stepName- name of the step- Returns:
- workflow step
-
containsStep
Description copied from interface:WorkflowContextChecks if a step with the given name exists in the workflow execution.- Specified by:
containsStepin interfaceWorkflowContext- Parameters:
stepName- name of the step- Returns:
- true if the step exists, false otherwise
-
processingContext
Internal access to processing context used by implemeters.- Returns:
- processing context.
-