Class SimpleWorkflowContext
java.lang.Object
io.axoniq.framework.workflow.runtime.execution.AbstractWorkflowContext
io.axoniq.framework.workflow.dsl.base.BaseWorkflowContext
io.axoniq.framework.workflow.dsl.simple.SimpleWorkflowContext
- All Implemented Interfaces:
WorkflowContext
Convenience Java DSL built on top of
BaseWorkflowContext.
This variant keeps the same workflow primitives as the base DSL, but adds shortcuts for common cases such as execute steps without extra input payload, waiting for a typed event, publishing an event given as payload, and replacing the workflow payload with a single object.
- Since:
- 5.4.0
- Author:
- Simon Zambrovski, Stefan Dragisic, Allrad Buijze, Steven van Beelen
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleWorkflowContext(String workflowId, Map<String, @Nullable Object> payload, ProcessingContext processingContext, WorkflowConfiguration<?> workflowConfiguration) Creates the simple workflow context for a single workflow instance. -
Method Summary
Modifier and TypeMethodDescription<T> TawaitEvent(String stepName, Class<T> eventType, Associations conditions, UnaryOperator<WaitForStepDefinition> customizer) Waits for an event of the given type that matches the provided association conditions and returns the converted event payload.<T> TawaitExecute(String stepName, Class<T> resultType, Supplier<T> action) Runs a synchronous action as a workflow step and returns its single result value as the requested type.voidawaitPublish(String stepName, Object payload) Publishes a business event given as payload and blocks until the step is recorded.voidawaitPublish(String stepName, Object payload, Metadata metadata) Publishes a business event given as payload and metadata and blocks until the step is recorded.voidawaitPublish(String stepName, EventMessage event) Publishes a business event as a durable workflow step and blocks until the step is recorded.voidCancels the workflow with a human-readable reason.execute(String stepName, PayloadProcessor processor) Starts an execute step with an empty step-local input payload.execute(String stepName, PayloadProcessor processor, UnaryOperator<ExecuteStepDefinition> customizer) Starts an execute step with an empty step-local input payload and a customized step definition.Publishes a business event given as payload.Publishes a business event given as payload and metadata.publish(String stepName, EventMessage event) Publishes a business event as a durable workflow step and returns a handle to await later.voidsetPayload(String stepName, Object value) Replaces the current workflow payload with the fields extracted from the given value.voidBlocks for the given duration without waiting for an external event.waitForEvent(String stepName, Class<?> eventType, Associations conditions) Waits for an event of the given type that matches the provided association conditions.waitForEvent(String stepName, Class<?> eventType, Associations conditions, UnaryOperator<WaitForStepDefinition> customizer) Waits for an event of the given type that matches the provided association conditions.Methods inherited from class io.axoniq.framework.workflow.dsl.base.BaseWorkflowContext
apply, awaitEvent, awaitEvent, awaitExecute, awaitExecute, awaitModifyPayload, awaitModifyPayload, awaitPublish, awaitSleep, cancel, cancel, cancelStep, cancelStep, defaultCancelStepDefinition, defaultCancelWorkflowDefinition, defaultExecuteStepDefinition, defaultFailWorkflowDefinition, defaultMigrateVersionStepDefinition, defaultPayloadStepDefinition, defaultPublishStepDefinition, defaultRetryPolicy, defaultTimeout, defaultWaitForStepDefinition, equalsTo, execute, execute, fail, fail, metadataProperty, migrateVersion, migrateVersion, modifyPayload, modifyPayload, payloadProperty, publish, resolve, setDefaultRetryPolicy, setDefaultTimeout, sleep, waitForEvent, waitForEventMethods inherited from class io.axoniq.framework.workflow.runtime.execution.AbstractWorkflowContext
allMatch, anyMatch, awaitEvent, awaitExecute, awaitModifyPayload, awaitPublish, cancel, cancelStep, containsStep, execute, fail, getStep, migrateVersion, modifyPayload, noneMatch, processingContext, publish, resolveComponent, waitForEvent, workflowDefinitionId, workflowId, workflowPayload, workflowStatus, workflowStepNames
-
Constructor Details
-
SimpleWorkflowContext
public SimpleWorkflowContext(String workflowId, Map<String, @Nullable Object> payload, ProcessingContext processingContext, WorkflowConfiguration<?> workflowConfiguration) Creates the simple workflow context for a single workflow instance.Applications normally receive this context from the runtime when a workflow definition is executed rather than constructing it directly.
- Parameters:
workflowId- unique identifier of the workflow instancepayload- initial workflow payloadprocessingContext- processing context for the current messageworkflowConfiguration- runtime configuration for this workflow
-
-
Method Details
-
execute
Starts an execute step with an empty step-local input payload.- Parameters:
stepName- logical name of the stepprocessor- function that performs the step work- Returns:
- handle for the running step
-
execute
public WorkflowStepResult execute(String stepName, PayloadProcessor processor, UnaryOperator<ExecuteStepDefinition> customizer) Starts an execute step with an empty step-local input payload and a customized step definition.- Parameters:
stepName- logical name of the stepprocessor- function that performs the step workcustomizer- customizer for timeout, mapping, retries, or metadata- Returns:
- handle for the running step
-
awaitExecute
Runs a synchronous action as a workflow step and returns its single result value as the requested type.This convenience method stores the action result under the internal key
"__" + stepName + "Result"in the step payload map and then unwraps that single value for the caller.- Type Parameters:
T- expected result type- Parameters:
stepName- logical name of the stepresultType- expected Java type of the resultaction- action to execute synchronously- Returns:
- typed result returned by the action
-
sleep
Blocks for the given duration without waiting for an external event.- Parameters:
stepName- logical name of the sleep steptimeout- time to wait before continuing
-
awaitEvent
public <T> T awaitEvent(String stepName, Class<T> eventType, Associations conditions, UnaryOperator<WaitForStepDefinition> customizer) Waits for an event of the given type that matches the provided association conditions and returns the converted event payload.- Type Parameters:
T- expected event payload type- Parameters:
stepName- logical name of the waiting stepeventType- expected event payload typeconditions- association constraints the event must satisfycustomizer- customizer for timeout, mapping, or metadata- Returns:
- converted event payload
-
waitForEvent
public WorkflowStepResult waitForEvent(String stepName, Class<?> eventType, Associations conditions, UnaryOperator<WaitForStepDefinition> customizer) Waits for an event of the given type that matches the provided association conditions.- Parameters:
stepName- logical name of the waiting stepeventType- expected event payload typeconditions- association constraints the event must satisfycustomizer- customizer for timeout, mapping, or metadata- Returns:
- handle for the waiting step
-
waitForEvent
public WorkflowStepResult waitForEvent(String stepName, Class<?> eventType, Associations conditions) Waits for an event of the given type that matches the provided association conditions.- Parameters:
stepName- logical name of the waiting stepeventType- expected event payload typeconditions- association constraints the event must satisfy- Returns:
- handle for the waiting step
-
setPayload
Replaces the current workflow payload with the fields extracted from the given value.- Parameters:
stepName- logical name of the payload update stepvalue- object whose properties become the new workflow payload
-
publish
Publishes a business event as a durable workflow step and returns a handle to await later.- Parameters:
stepName- logical name of the publish stepevent- event to publish- Returns:
- handle for the publish step
- See Also:
-
publish
Publishes a business event given as payload. TheMessageTypeis resolved through the configuredMessageTypeResolver.- Parameters:
stepName- logical name of the publish steppayload- event payload- Returns:
- handle for the publish step
-
publish
Publishes a business event given as payload and metadata. TheMessageTypeis resolved through the configuredMessageTypeResolver; the engine's workflow metadata keys override entries of the same name.- Parameters:
stepName- logical name of the publish steppayload- event payloadmetadata- metadata to publish with the event- Returns:
- handle for the publish step
-
awaitPublish
Publishes a business event as a durable workflow step and blocks until the step is recorded.- Parameters:
stepName- logical name of the publish stepevent- event to publish- See Also:
-
awaitPublish
Publishes a business event given as payload and blocks until the step is recorded.- Parameters:
stepName- logical name of the publish steppayload- event payload- See Also:
-
awaitPublish
Publishes a business event given as payload and metadata and blocks until the step is recorded.- Parameters:
stepName- logical name of the publish steppayload- event payloadmetadata- metadata to publish with the event- See Also:
-
cancel
Cancels the workflow with a human-readable reason.- Parameters:
reason- descriptive reason for the cancellation- Throws:
WorkflowCancelledException- always, after the cancellation event is published
-