004 电商平台核心链路_StateMachine(二)
SpringStateMachine结合UML
springStateMachine2.X开始支持与UML结合,大大方便了对其的应用,在1.X的版本中大量繁杂的定义状态、action等等内容都得到了很好的解决;
step1 eclipse安装Papyrus插件
安装完成后:
官方说明:https://docs.spring.io/spring-statemachine/docs/2.0.4.RELEASE/reference/htmlsingle/
Defining a state machine configuration with UI modeling is supported via Eclipse Papyrus framework.From eclipse wizard create a new Papyrus Model with UML Diagram Language. In this example it’s named as simple-machine. Then you’ve given an option to choose various diagram kind’s and a StateMachine Diagram must be chosen.We want to create a machine having two states, S1 and S2 where S1 is initial state. Then event E1 is created to do a transition from S1 to S2. In papyrus a machine would then look like something shown below.
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_AMP3IP8fEeW45bORGB4c_A" name="RootElement"><packagedElement xmi:type="uml:StateMachine" xmi:id="_AMRFQP8fEeW45bORGB4c_A" name="StateMachine"><region xmi:type="uml:Region" xmi:id="_AMRsUP8fEeW45bORGB4c_A" name="Region1"><transition xmi:type="uml:Transition" xmi:id="_chgcgP8fEeW45bORGB4c_A" source="_EZrg4P8fEeW45bORGB4c_A" target="_FAvg4P8fEeW45bORGB4c_A"><trigger xmi:type="uml:Trigger" xmi:id="_hs5jUP8fEeW45bORGB4c_A" event="_NeH84P8fEeW45bORGB4c_A"/></transition><transition xmi:type="uml:Transition" xmi:id="_egLIoP8fEeW45bORGB4c_A" source="_Fg0IEP8fEeW45bORGB4c_A" target="_EZrg4P8fEeW45bORGB4c_A"/><subvertex xmi:type="uml:State" xmi:id="_EZrg4P8fEeW45bORGB4c_A" name="S1"/><subvertex xmi:type="uml:State" xmi:id="_FAvg4P8fEeW45bORGB4c_A" name="S2"/><subvertex xmi:type="uml:Pseudostate" xmi:id="_Fg0IEP8fEeW45bORGB4c_A"/></region></packagedElement><packagedElement xmi:type="uml:Signal" xmi:id="_L01D0P8fEeW45bORGB4c_A" name="E1"/><packagedElement xmi:type="uml:SignalEvent" xmi:id="_NeH84P8fEeW45bORGB4c_A" name="SignalEventE1" signal="_L01D0P8fEeW45bORGB4c_A"/>
</uml:Model>
自动生成xml,不需要书写其余代码,但是要将生成的UML.xml文件加载;
step2 应用Papyrus创建UML
在工程内创建UML文件目录 resources/model,并new一个Papyrus Model >model目录右键>new>other>
创建完成后打开XX.di文件,运行Create View;
开始绘制:
step3 配置状态config
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.statemachine.config.EnableStateMachine;
import org.springframework.statemachine.config.StateMachineConfigurerAdapter;
import org.springframework.statemachine.config.builders.StateMachineModelConfigurer;
import org.springframework.statemachine.config.model.StateMachineModelFactory;
import org.springframework.statemachine.uml.UmlStateMachineModelFactory;@Configuration
@EnableStateMachine
public class StateMachineSimpleConfig extends StateMachineConfigurerAdapter<String, String> {//配置@Overridepublic void configure(StateMachineModelConfigurer<String, String> model) throws Exception {model.withModel().factory(modelFactory());}//通过Resource创建model对象,传入UML文件地址@Beanpublic StateMachineModelFactory<String, String> modelFactory() {Resource model = new ClassPathResource("model/sm-simple.uml");return new UmlStateMachineModelFactory(model);}}
step4 创建监听
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.OnTransitionEnd;
import org.springframework.statemachine.annotation.OnTransitionStart;
import org.springframework.statemachine.annotation.WithStateMachine;@WithStateMachine
public class StateMachineSimpleListener {//监听执行器@OnTransition(target = "T1")public void init() {System.err.println("--------- INIT T1 -----------");}//监听执行器@OnTransition(source = "T1", target = "T2")public void create() {System.err.println("---------T1 -> T2-----------");}//监听执行器@OnTransition(source = "T2", target = "T3")public void S2toS5() {System.err.println("---------T2 -> T3---------");}}
step5 测试
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.statemachine.StateMachine;
import org.springframework.test.context.junit4.SpringRunner;import com.bfxy.statemachine.constant.Events;
import com.bfxy.statemachine.constant.States;@RunWith(SpringRunner.class)
@SpringBootTest
public class ApplicationTests {@Testpublic void contextLoads() {}//注入的stateMachineSimple名字必须与UML文件名字一致@Autowiredprivate StateMachine<String, String> stateMachineSimple;@Testpublic void testSimple() throws Exception {stateMachineSimple.start();stateMachineSimple.sendEvent(MessageBuilder.withPayload("K1").build());stateMachineSimple.sendEvent(MessageBuilder.withPayload("K2").build());}}
004 电商平台核心链路_StateMachine(二)相关推荐
- 001 电商平台核心链路_整体架构设计
应用微服务构建电商平台,用户在业务入口提交订单请求 ,请求进入订单平台处理并落地入库,然后发送创建消息给下游服务,MQ服务将创建通知发送至物流平台处理(每层服务链路都是如此流程),物流通过MQ进入调度 ...
- 国家出台电子商务法,解决电商平台“二选一”问题
近日,电子商务法草案第三次提交全国人大常委会进行审议.在三审稿中,对电商平台要求商家"二选一"的行为进行了规范. 电商平台"二选一"具体是指,在电商促销活动中, ...
- 电商平台不是电商,商家应如何看待电商的崛起?
也许你总会刷到一些电商平台水军,他们喜欢把实体不行归咎于高铺租和电商平台的冲击,仿佛有了电商平台就可以绕过铺租,就是未来的救世主一样.为什么我会说这些人是电商平台的水军呢,因为这些鼓吹手们总是会有意无 ...
- 工业制造行业B2B电商平台解决方案
揭示工业制造业的发展趋势 -- 数据显示,近年来,我国工业增加值与增速出现了几次不同程度的上涨,一改往常持续下降的局面.国内整个工业制造业正在逐渐复苏,同时随着国家在政策层面持续加码促进大型工业制造业 ...
- 数商云工业制造行业B2B电商平台解决方案
揭示工业制造业的发展趋势: 数据显示,自从进入2017年,我国工业增加值与增速出现了几次不同程度的上涨,一改往常持续下降的局面.国内整个工业制造业正在逐渐复苏,同时随着国家在政策层面持续加码促进大型工 ...
- 传统企业的移动电商平台实践
本文首发在 freshmanTechnology .感谢中生代的邀请,也就促成了本文. 作者 郝振明 摘要:随着电商领域在传统企业的热度不断上升,在"互联网+"的背景下,许多传统企 ...
- 禁止电商平台二选一、遛狗必栓绳!5月起有这些新规定
5月起,有一批新的法律法规即将落地,这将如何影响我们的生活,一起来看看吧. "直播带货"主播应满十六周岁 国家互联网信息办公室.公安部.商务部.文化和旅游部.国家税务总局.国家市场 ...
- 电商平台“二选一” 最后买单的却是商家和消费者
TechWeb 4月27日 文/小渔 拼多多日前对外发布上市后的首份年报,各项数据仍是保持着高速增长的势头.与此同时,创始人黄峥也发布了上市后首封致股东信,言语中透露出对市场中存在的"二选 ...
- 前端网页设计内容二《电商平台网站》
讲重点.展示页面效果.代码编译. 看页面效果: 今天的 重点在最后一个页面. 看代码: <!DOCTYPE html> <html lang="zh">&l ...
最新文章
- 二维数组练习--矩阵的加法和乘法
- python-15:装饰函数之一
- 菜鸟教程python3 mysql_Python 操作 MySQL 数据库
- android:background=@color/white [create file color.xml at res/values/]
- 图解ARP协议(五)免费ARP:地址冲突了肿么办?
- 简单存取款机的实现---控制输入变量的规则
- VMware设置及linux静态ip设置
- 几个提升Go业务开发效率的流行框架和开源库
- matlab分析xml文件_如何在Java中读取XML文件(DOM分析器)
- 通过ISA发布服务器(二)
- mysql事务的两点特性_MySQL基础篇(06):事务管理,锁机制案例详解
- DTC标准故障码格式解析
- 『概率知识』伯努利试验及n重伯努利试验+方差协方差理解!
- ModelCoder模块系列:PID模块介绍
- Stratified Transformer复现和调试记录,ubuntu20复现S3DIS数据集(点云语义分割)
- py-faster-rcnn 中 shell脚本解读:./experiments/scripts/faster_rcnn_alt_opt.sh
- 医学图像处理:CT与CBCT
- 2021年高考成绩查询襄阳状元,2021年襄阳高考状元是谁分数多少分,历年襄阳高考状元名单...
- dvi dp hdmi_HDMI vs DisplayPort vs DVI:您要在新计算机上使用哪个端口?
- 关于实习和秋招的准备