Class WorkflowRuntimeBuilder

java.lang.Object
io.dapr.workflows.runtime.WorkflowRuntimeBuilder

public class WorkflowRuntimeBuilder extends Object
  • Constructor Details

    • WorkflowRuntimeBuilder

      public WorkflowRuntimeBuilder()
      Constructs the WorkflowRuntimeBuilder.
    • WorkflowRuntimeBuilder

      public WorkflowRuntimeBuilder(Properties properties)
      Constructs the WorkflowRuntimeBuilder.
      Parameters:
      properties - Properties to use.
    • WorkflowRuntimeBuilder

      public WorkflowRuntimeBuilder(org.slf4j.Logger logger)
  • Method Details

    • build

      public WorkflowRuntime build()
      Returns a WorkflowRuntime object.

      The runtime is shared: while one is open, every call returns that same instance. Once it has been closed, the next call builds a new runtime, which allows a full restart (for example on a live reload or between tests). Closing a runtime also shuts down the channel of the builder that created it, so the new runtime must be built from a new builder.

      Returns:
      A WorkflowRuntime object.
      Throws:
      IllegalStateException - if a new runtime is needed but this builder's channel has already been shut down by a previous runtime.
    • withExecutorService

      public WorkflowRuntimeBuilder withExecutorService(ExecutorService executorService)
      Register Executor Service to use with workflow.
      Parameters:
      executorService - to be used.
      Returns:
      WorkflowRuntimeBuilder.
    • withStatefulHistoryDisabled

      public WorkflowRuntimeBuilder withStatefulHistoryDisabled(boolean disableStatefulHistory)
      Disables the stateful-history optimization.

      By default the worker advertises WORKER_CAPABILITY_STATEFUL_HISTORY and caches each instance's committed history per work-item stream, so the sidecar can send only the new events (the delta) each turn instead of the full history. A cache miss is always recovered safely via the GetInstanceHistory RPC, so disabling this only affects per-turn bandwidth, never correctness. When disabled, the worker always receives the full history.

      Parameters:
      disableStatefulHistory - whether to disable the stateful-history optimization
      Returns:
      WorkflowRuntimeBuilder.
    • withHistoryCacheTtl

      public WorkflowRuntimeBuilder withHistoryCacheTtl(Duration historyCacheTtl)
      Sets the sliding time-to-live for cached instance histories. An instance's entry is reclaimed once it has gone idle (no turn) for longer than this. If not specified, a default of one hour is used. Ignored when the stateful-history optimization is disabled.
      Parameters:
      historyCacheTtl - the sliding time-to-live for a cached instance history
      Returns:
      WorkflowRuntimeBuilder.
    • withHistoryCacheMaxInstances

      public WorkflowRuntimeBuilder withHistoryCacheMaxInstances(int historyCacheMaxInstances)
      Sets the maximum number of per-instance histories retained on a single work-item stream; least-recently-used entries are evicted beyond it. A non-positive value uses the built-in default. Ignored when the stateful-history optimization is disabled.
      Parameters:
      historyCacheMaxInstances - the instance-count cap for the history cache
      Returns:
      WorkflowRuntimeBuilder.
    • withHistoryCacheMaxBytes

      public WorkflowRuntimeBuilder withHistoryCacheMaxBytes(long historyCacheMaxBytes)
      Sets the byte budget for cached histories on a single work-item stream; least-recently-used entries are evicted beyond it. A non-positive value means unlimited (bounded only by the instance-count cap and the TTL). Ignored when the stateful-history optimization is disabled.
      Parameters:
      historyCacheMaxBytes - the byte budget for the history cache
      Returns:
      WorkflowRuntimeBuilder.
    • registerWorkflow

      public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(Class<T> clazz)
      Registers a Workflow object.
      Type Parameters:
      T - any Workflow type
      Parameters:
      clazz - the class being registered
      Returns:
      the WorkflowRuntimeBuilder
    • registerWorkflow

      public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(String name, Class<T> clazz)
      Registers a Workflow object.
      Type Parameters:
      T - any Workflow type
      Parameters:
      name - the name of the workflow to register
      clazz - the class being registered
      Returns:
      the WorkflowRuntimeBuilder
    • registerWorkflow

      public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(String name, Class<T> clazz, String versionName, Boolean isLatestVersion)
      Registers a Workflow object.
      Type Parameters:
      T - any Workflow type
      Parameters:
      name - the name of the workflow to register
      clazz - the class being registered
      versionName - the version name of the workflow
      isLatestVersion - whether the workflow is the latest version
      Returns:
      the WorkflowRuntimeBuilder
    • registerWorkflow

      public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(T instance)
      Registers a Workflow object.
      Type Parameters:
      T - any Workflow type
      Parameters:
      instance - the workflow instance being registered
      Returns:
      the WorkflowRuntimeBuilder
    • registerWorkflow

      public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(String name, T instance, String versionName, Boolean isLatestVersion)
      Registers a Workflow object.
      Type Parameters:
      T - any Workflow type
      Parameters:
      name - the name of the workflow to register
      instance - the workflow instance being registered
      versionName - the version name of the workflow
      isLatestVersion - whether the workflow is the latest version
      Returns:
      the WorkflowRuntimeBuilder
    • registerActivity

      public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(Class<T> clazz)
      Registers an Activity object.
      Type Parameters:
      T - any WorkflowActivity type
      Parameters:
      clazz - the class being registered
      Returns:
      the WorkflowRuntimeBuilder
    • registerActivity

      public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(String name, Class<T> clazz)
      Registers an Activity object.
      Type Parameters:
      T - any WorkflowActivity type
      Parameters:
      name - Name of the activity to register.
      clazz - Class of the activity to register.
      Returns:
      the WorkflowRuntimeBuilder
    • registerActivity

      public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(T instance)
      Registers an Activity object.
      Type Parameters:
      T - any WorkflowActivity type
      Parameters:
      instance - the class instance being registered
      Returns:
      the WorkflowRuntimeBuilder
    • registerActivity

      public <T extends WorkflowActivity> WorkflowRuntimeBuilder registerActivity(String name, T instance)
      Registers an Activity object.
      Type Parameters:
      T - any WorkflowActivity type
      Parameters:
      name - Name of the activity to register.
      instance - the class instance being registered
      Returns:
      the WorkflowRuntimeBuilder
    • registerTaskActivityFactory

      public WorkflowRuntimeBuilder registerTaskActivityFactory(String activityName, TaskActivityFactory taskActivityFactory)
      Registers a Task Activity using a TaskActivityFactory.

      This method allows advanced use cases where activities are created dynamically or require custom instantiation logic instead of relying on class-based or instance-based registration.

      Parameters:
      activityName - the logical name of the activity to register
      taskActivityFactory - the factory responsible for creating the activity
      Returns:
      the WorkflowRuntimeBuilder
    • registerTaskOrchestrationFactory

      public WorkflowRuntimeBuilder registerTaskOrchestrationFactory(String orchestrationName, TaskOrchestrationFactory taskOrchestrationFactory)
      Registers a Task Orchestration using a TaskOrchestrationFactory.

      This method is intended for advanced scenarios where orchestrations are created programmatically or require custom construction logic, rather than being registered via workflow classes or instances.

      Parameters:
      orchestrationName - the logical name of the orchestration to register
      taskOrchestrationFactory - the factory responsible for creating the orchestration
      Returns:
      the WorkflowRuntimeBuilder