Class SimpleWorkflowContext

All Implemented Interfaces:
WorkflowContext

public class SimpleWorkflowContext extends BaseWorkflowContext
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 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 instance
      payload - initial workflow payload
      processingContext - processing context for the current message
      workflowConfiguration - runtime configuration for this workflow
  • Method Details

    • execute

      public WorkflowStepResult execute(String stepName, PayloadProcessor processor)
      Starts an execute step with an empty step-local input payload.
      Parameters:
      stepName - logical name of the step
      processor - 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 step
      processor - function that performs the step work
      customizer - customizer for timeout, mapping, retries, or metadata
      Returns:
      handle for the running step
    • awaitExecute

      public <T> T awaitExecute(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.

      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 step
      resultType - expected Java type of the result
      action - action to execute synchronously
      Returns:
      typed result returned by the action
    • sleep

      public void sleep(String stepName, Duration timeout)
      Blocks for the given duration without waiting for an external event.
      Parameters:
      stepName - logical name of the sleep step
      timeout - 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 step
      eventType - expected event payload type
      conditions - association constraints the event must satisfy
      customizer - 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 step
      eventType - expected event payload type
      conditions - association constraints the event must satisfy
      customizer - 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 step
      eventType - expected event payload type
      conditions - association constraints the event must satisfy
      Returns:
      handle for the waiting step
    • setPayload

      public void setPayload(String stepName, Object value)
      Replaces the current workflow payload with the fields extracted from the given value.
      Parameters:
      stepName - logical name of the payload update step
      value - object whose properties become the new workflow payload
    • publish

      public WorkflowStepResult publish(String stepName, EventMessage event)
      Publishes a business event as a durable workflow step and returns a handle to await later.
      Parameters:
      stepName - logical name of the publish step
      event - event to publish
      Returns:
      handle for the publish step
      See Also:
    • publish

      public WorkflowStepResult publish(String stepName, Object payload)
      Publishes a business event given as payload. The MessageType is resolved through the configured MessageTypeResolver.
      Parameters:
      stepName - logical name of the publish step
      payload - event payload
      Returns:
      handle for the publish step
    • publish

      public WorkflowStepResult publish(String stepName, Object payload, Metadata metadata)
      Publishes a business event given as payload and metadata. The MessageType is resolved through the configured MessageTypeResolver; the engine's workflow metadata keys override entries of the same name.
      Parameters:
      stepName - logical name of the publish step
      payload - event payload
      metadata - metadata to publish with the event
      Returns:
      handle for the publish step
    • awaitPublish

      public void awaitPublish(String stepName, EventMessage event)
      Publishes a business event as a durable workflow step and blocks until the step is recorded.
      Parameters:
      stepName - logical name of the publish step
      event - event to publish
      See Also:
    • awaitPublish

      public void awaitPublish(String stepName, Object payload)
      Publishes a business event given as payload and blocks until the step is recorded.
      Parameters:
      stepName - logical name of the publish step
      payload - event payload
      See Also:
    • awaitPublish

      public void awaitPublish(String stepName, Object payload, Metadata metadata)
      Publishes a business event given as payload and metadata and blocks until the step is recorded.
      Parameters:
      stepName - logical name of the publish step
      payload - event payload
      metadata - metadata to publish with the event
      See Also:
    • cancel

      public void cancel(String reason)
      Cancels the workflow with a human-readable reason.
      Parameters:
      reason - descriptive reason for the cancellation
      Throws:
      WorkflowCancelledException - always, after the cancellation event is published