Class DefaultFlowInstanceService

java.lang.Object
cloud.opencode.base.flow.internal.DefaultFlowInstanceService
All Implemented Interfaces:
FlowInstanceService

public final class DefaultFlowInstanceService extends Object implements FlowInstanceService
Default FlowInstanceService implementation. 默认 FlowInstanceService 实现。

R3 SEC P0-2 / P0-5: when a non-no-op CurrentUserProvider is wired, terminate / get / findByInitiator enforce that the caller is the instance initiator (or admin). CurrentUserProvider.NO_OP reverts to the legacy permissive behaviour for backward compatibility.

R3 SEC P0-2 / P0-5:装配真实 CurrentUserProvider 时引擎对 terminate/get/findByInitiator 强制按发起人鉴权;NO_OP 退化为兼容模式。

Since:
JDK 25, opencode-base-flow V1.0.5
Author:
Leon Soo
  • Constructor Details

    • DefaultFlowInstanceService

      public DefaultFlowInstanceService(FlowRepository repo, AssigneeResolver assigneeResolver, ExpressionEvaluator exprEvaluator)
      Convenience constructor that wires a no-op FlowMetrics. 便利构造器:默认使用 no-op FlowMetrics。
      Parameters:
      repo - persistence facade — 持久化门面
      assigneeResolver - assignee resolver SPI — 参与者解析 SPI
      exprEvaluator - optional expression evaluator — 可选表达式 SPI
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultFlowInstanceService

      public DefaultFlowInstanceService(FlowRepository repo, AssigneeResolver assigneeResolver, ExpressionEvaluator exprEvaluator, FlowMetrics metrics)
      Convenience constructor with an explicit FlowMetrics. 便利构造器:显式注入 FlowMetrics。
      Parameters:
      repo - persistence facade — 持久化门面
      assigneeResolver - assignee resolver SPI — 参与者解析 SPI
      exprEvaluator - optional expression evaluator SPI — 可选表达式 SPI
      metrics - metrics sink — 指标接收器
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultFlowInstanceService

      public DefaultFlowInstanceService(FlowRepository repo, AssigneeResolver assigneeResolver, ExpressionEvaluator exprEvaluator, FlowMetrics metrics, CurrentUserProvider currentUser)
      Full convenience constructor including authn SPI. 完整便利构造器(含认证 SPI)。
      Parameters:
      repo - persistence facade — 持久化门面
      assigneeResolver - assignee resolver SPI — 参与者解析 SPI
      exprEvaluator - optional expression evaluator SPI — 可选表达式 SPI
      metrics - metrics sink — 指标接收器
      currentUser - current-user SPI — 当前用户 SPI
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultFlowInstanceService

      public DefaultFlowInstanceService(FlowRepository repo, StepEntry stepEntry, HistoryWriter history, cloud.opencode.base.flow.internal.IdProvider idProvider)
      Test-friendly constructor. 测试友好构造器。
      Parameters:
      repo - persistence facade — 持久化门面
      stepEntry - step entry helper — 节点进入工具
      history - history writer — 历史追加器
      idProvider - id provider — id 提供者
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultFlowInstanceService

      public DefaultFlowInstanceService(FlowRepository repo, StepEntry stepEntry, HistoryWriter history, cloud.opencode.base.flow.internal.IdProvider idProvider, FlowMetrics metrics)
      Test-friendly constructor with explicit FlowMetrics. 测试友好构造器:显式注入 FlowMetrics。
      Parameters:
      repo - persistence facade — 持久化门面
      stepEntry - step entry helper — 节点进入工具
      history - history writer — 历史追加器
      idProvider - id provider — id 提供者
      metrics - metrics sink — 指标接收器
      Since:
      JDK 25, opencode-base-flow V1.0.5
    • DefaultFlowInstanceService

      public DefaultFlowInstanceService(FlowRepository repo, StepEntry stepEntry, HistoryWriter history, cloud.opencode.base.flow.internal.IdProvider idProvider, FlowMetrics metrics, CurrentUserProvider currentUser)
      Full test-friendly constructor including authn SPI. 完整测试构造器(含认证 SPI)。
      Parameters:
      repo - persistence facade — 持久化门面
      stepEntry - step entry helper — 节点进入工具
      history - history writer — 历史追加器
      idProvider - id provider — id 提供者
      metrics - metrics sink — 指标接收器
      currentUser - current-user SPI — 当前用户 SPI
      Since:
      JDK 25, opencode-base-flow V1.0.5
  • Method Details

    • start

      public FlowInstance start(String flowKey, String initiatorId, Map<String,Object> variables)
      Description copied from interface: FlowInstanceService
      Start a new instance for the given business key. 启动一个新实例。
      Specified by:
      start in interface FlowInstanceService
      Parameters:
      flowKey - business key — 业务 key
      initiatorId - initiator user id — 发起人
      variables - business variables (nullable) — 业务变量(可空)
      Returns:
      persisted instance — 已持久化实例
    • get

      public FlowInstance get(String instanceId)
      Description copied from interface: FlowInstanceService
      Returns the instance by id (or throws INST_NOT_FOUND). 按 id 返回实例(不存在抛 INST_NOT_FOUND)。
      Specified by:
      get in interface FlowInstanceService
      Parameters:
      instanceId - instance id — 实例 ID
      Returns:
      instance — 实例
    • findByInitiator

      public List<FlowInstance> findByInitiator(String userId, int page, int size)
      Description copied from interface: FlowInstanceService
      Paginated list of instances started by the given user. 分页查询某发起人启动的实例。
      Specified by:
      findByInitiator in interface FlowInstanceService
      Parameters:
      userId - initiator user id — 发起人
      page - zero-based page — 页码(0 起)
      size - page size — 每页大小
      Returns:
      instances on the requested page — 该页实例
    • terminate

      public void terminate(String instanceId, String operatorId, String reason)
      Description copied from interface: FlowInstanceService
      Terminate the running instance (out-of-band). Cancels every PENDING task; writes a history record. 终止运行中的实例(外部操作)。取消所有 PENDING task;写一条 history。
      Specified by:
      terminate in interface FlowInstanceService
      Parameters:
      instanceId - instance id — 实例 ID
      operatorId - operator user id — 操作人
      reason - reason (nullable) — 理由