workflow - StateRepository 状态持久化
2025年12月21日 下午4:30:52
StateRepository 接口,状态仓库接口。提供流程节点状态的持久化支持。内置实现有:
- InMemoryStateRepository,内存适配的状态仓库
- RedisStateRepository,Redis 适配的状态仓库
1、StateRepository 使用示例
WorkflowService work = WorkflowService.of(engine,
new ActorStateController(),
new InMemoryStateRepository());
FlowContext context = FlowContext.of("i1").put("actor", "@admin");
Graph graph = engine.getGraph("g1");
//1. 取出任务
Task task = work.getTask(graph, context);
//2. 提交任务
work.postTask(task.getNode(), TaskAction.FORWARD, context);
2、StateRepository 接口字典(定制参考)
public interface StateRepository {
/**
* 状态获取
*/
StateType stateGet(FlowContext context, Node node);
/**
* 状态推入
*/
void statePut(FlowContext context, Node node, StateType state);
/**
* 状态移除
*/
void stateRemove(FlowContext context, Node node);
/**
* 状态清空
*/
void stateClear(FlowContext context);
}