前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >spring-state-machine持久化restore踩坑

spring-state-machine持久化restore踩坑

作者头像
阿超
发布2023-12-25 09:59:51
2340
发布2023-12-25 09:59:51
举报
文章被收录于专栏:快乐阿超

没有人事先了解自己到底有多大的力量,直到他试过以后才知道。——歌德

今天遇到的问题是在响应式编程中发生禁止block异常:

代码语言:javascript
复制
org.springframework.statemachine.persist.AbstractStateMachinePersister#restore

源码如下:

代码语言:javascript
复制
@Override
public final StateMachine<S, E> restore(StateMachine<S, E> stateMachine, T contextObj) throws Exception {
	final StateMachineContext<S, E> context = stateMachinePersist.read(contextObj);
	stateMachine.stopReactively().block();
	stateMachine.getStateMachineAccessor().doWithAllRegions(function -> function.resetStateMachineReactively(context).block());
	stateMachine.startReactively().block();
	return stateMachine;
}

自己重新编写该功能

代码语言:javascript
复制
public Mono<StateMachine<StateEnum, WordChain>> restore(StateMachine<WordChainStateEnuminEventEnum> stateMaring contextObj) {
    return stateMachine.stopReactively().then(Mono.fromSupplier((SerSupp<StateMachineContext<WordChainStateEnum, WordChainEventEn                    ateMachineRuntimePersister.read(contextObj))).flatMapMany(context ->
                    Flux.fromIterable(stateMachine.getStateMachineAccessor().withAllRegions())
                            .flatMap(function -> function.resetStateMachineReactively(context)))
            .then(stateMachine.startReactively()).thenReturn(stateMachine);
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-12-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档