Class Workflow<S>

Object
akka.javasdk.workflow.Workflow<S>
Type Parameters:
S - The type of the state for this workflow.

public abstract class Workflow<S> extends Object
Workflows are stateful components and are defined by a set of steps and transitions between them.

You can use workflows to implement business processes that span multiple services.

When implementing a workflow, you define a state type and a set of steps. Each step defines a call to be executed and the transition to the next step based on the result of the call. The workflow state can be updated after each successful step execution.

The runtime keeps track of the state of the workflow and the current step. If the workflow is stopped for any reason, it can be resumed from the last known state and step.

Workflow methods that handle incoming commands should return an Workflow.Effect describing the next processing actions.

Concrete classes can accept the following types to the constructor:

Concrete class must be annotated with ComponentId.

  • Constructor Details

    • Workflow

      public Workflow()
  • Method Details

    • step

      public StepBuilder step(String name)
      Start a step definition with a given step name.
      Parameters:
      name - Step name.
      Returns:
      Step builder.
    • emptyState

      public S emptyState()
      Returns the initial empty state object. This object will be passed into the command and step handlers, until a new state replaces it.

      Also known as "zero state" or "neutral state".

      The default implementation of this method returns null. It can be overridden to return a more sensible initial state.

    • commandContext

      protected final CommandContext commandContext()
      Additional context and metadata for a command handler.

      It will throw an exception if accessed from constructor.

      Throws:
      IllegalStateException - if accessed outside a handler method
    • timers

      public final TimerScheduler timers()
      Returns a TimerScheduler that can be used to schedule further in time.
    • currentState

      protected final S currentState()
      Returns the state as currently stored.

      Note that modifying the state directly will not update it in storage. To save the state, one must call {effects().updateState()}.

      This method can only be called when handling a command. Calling it outside a method (eg: in the constructor) will raise a IllegalStateException exception.

      Throws:
      IllegalStateException - if accessed outside a handler method
    • definition

      public abstract Workflow.WorkflowDef<S> definition()
      Returns:
      A workflow definition in a form of steps and transitions between them.
    • effects

      protected final Workflow.Effect.Builder<S> effects()
    • workflow

      public Workflow.WorkflowDef<S> workflow()
    • maxRetries

      public Workflow.RecoverStrategy.MaxRetries maxRetries(int maxRetries)
      Starts defining a recover strategy for the workflow or a specific step.
      Parameters:
      maxRetries - number of retries before giving up.
      Returns:
      MaxRetries strategy.