enhancement #I40DWO 流程配置文件中增加业务描述,打印步骤中带入业务描述

This commit is contained in:
bryan31
2021-07-27 00:30:21 +08:00
parent f03beb494f
commit d38ccdfdc0
11 changed files with 203 additions and 50 deletions

View File

@@ -1,5 +1,6 @@
package com.yomahub.liteflow.annotation;
import cn.hutool.core.annotation.Alias;
import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;
@@ -17,11 +18,11 @@ import java.lang.annotation.*;
@Component
public @interface LiteflowComponent {
@AliasFor(annotation = Component.class)
@AliasFor(annotation = Component.class, attribute = "value")
String value() default "";
@AliasFor("value")
String id();
@AliasFor(annotation = Component.class, attribute = "value")
String id() default "";
String name() default "";
}

View File

@@ -53,7 +53,7 @@ public abstract class NodeComponent {
public void execute() throws Exception{
Slot slot = this.getSlot();
LOG.info("[{}]:[O]start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName());
slot.addStep(new CmpStep(nodeId, CmpStepType.SINGLE));
slot.addStep(new CmpStep(nodeId, name, CmpStepType.SINGLE));
StopWatch stopWatch = new StopWatch();
stopWatch.start();
@@ -71,7 +71,6 @@ public abstract class NodeComponent {
stopWatch.stop();
// slot.addStep(new CmpStep(nodeId, CmpStepType.END));
final long timeSpent = stopWatch.getTotalTimeMillis();
// 性能统计
if (ObjectUtil.isNotNull(monitorBus)) {

View File

@@ -9,11 +9,11 @@ package com.yomahub.liteflow.entity.data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* Slot的抽象类实现
@@ -42,7 +42,7 @@ public abstract class AbsSlot implements Slot {
private static final String EXCEPTION = "exception";
private Deque<CmpStep> executeSteps = new ArrayDeque<CmpStep>();
private final Queue<CmpStep> executeSteps = new ConcurrentLinkedQueue<>();
protected ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap<String, Object>();
@@ -138,7 +138,7 @@ public abstract class AbsSlot implements Slot {
return (String)dataMap.get(REQUEST_ID);
}
public Deque<CmpStep> getExecuteSteps() {
public Queue<CmpStep> getExecuteSteps() {
return executeSteps;
}

View File

@@ -1,6 +1,7 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
*
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
@@ -10,62 +11,81 @@ package com.yomahub.liteflow.entity.data;
import java.text.MessageFormat;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
/**
* 组件步骤对象
* @author Bryan.Zhang
*/
public class CmpStep {
private String nodeId;
private CmpStepType stepType;
private String nodeId;
public CmpStep(String nodeId, CmpStepType stepType) {
this.nodeId = nodeId;
this.stepType = stepType;
}
private String nodeName;
public String getNodeId() {
return nodeId;
}
private CmpStepType stepType;
public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
public CmpStep(String nodeId, String nodeName, CmpStepType stepType) {
this.nodeId = nodeId;
this.nodeName = nodeName;
this.stepType = stepType;
}
public CmpStepType getStepType() {
return stepType;
}
public String getNodeId() {
return nodeId;
}
public void setStepType(CmpStepType stepType) {
this.stepType = stepType;
}
public void setNodeId(String nodeId) {
this.nodeId = nodeId;
}
@Override
public String toString() {
if(stepType.equals(CmpStepType.SINGLE)) {
return MessageFormat.format("{0}", nodeId);
}else {
return MessageFormat.format("{0}({1})", nodeId,stepType);
}
public CmpStepType getStepType() {
return stepType;
}
public void setStepType(CmpStepType stepType) {
this.stepType = stepType;
}
}
public String getNodeName() {
return nodeName;
}
@Override
public boolean equals(Object obj) {
if (ObjectUtil.isNull(obj)) {
return false;
}else {
if(getClass() != obj.getClass()) {
return false;
}else {
if(((CmpStep)obj).getNodeId().equals(this.getNodeId())) {
return true;
}else {
return false;
}
public void setNodeName(String nodeName) {
this.nodeName = nodeName;
}
@Override
public String toString() {
if (stepType.equals(CmpStepType.SINGLE)) {
if (StrUtil.isBlank(nodeName)){
return StrUtil.format("{}", nodeId);
}else{
return StrUtil.format("{}[{}]", nodeId, nodeName);
}
}
}
} else {
if (StrUtil.isBlank(nodeName)){
return StrUtil.format("{}({})", nodeId, stepType);
}else{
return StrUtil.format("{}[{}]({})", nodeId, nodeName, stepType);
}
}
}
@Override
public boolean equals(Object obj) {
if (ObjectUtil.isNull(obj)) {
return false;
} else {
if (getClass() != obj.getClass()) {
return false;
} else {
if (((CmpStep) obj).getNodeId().equals(this.getNodeId())) {
return true;
} else {
return false;
}
}
}
}
}

View File

@@ -0,0 +1,39 @@
package com.yomahub.liteflow.test.liteflowcomponent;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.entity.data.DefaultSlot;
import com.yomahub.liteflow.entity.data.LiteflowResponse;
import com.yomahub.liteflow.test.BaseTest;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
/**
* 测试springboot下的enable参数
* @author Bryan.Zhang
* @since 2.5.10
*/
@RunWith(SpringRunner.class)
@TestPropertySource(value = "classpath:/liteflowComponent/application.properties")
@SpringBootTest(classes = LiteflowComponentSpringbootTest.class)
@EnableAutoConfiguration
@ComponentScan({"com.yomahub.liteflow.test.liteflowComponent.cmp"})
public class LiteflowComponentSpringbootTest extends BaseTest {
@Autowired
private FlowExecutor flowExecutor;
@Test
public void testConfig() {
LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
Assert.assertTrue(response.isSuccess());
Assert.assertEquals("a[A组件]==>b[B组件]==>c[C组件]==>b[B组件]==>a[A组件]==>d", response.getSlot().printStep());
}
}

View File

@@ -0,0 +1,20 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.liteflowcomponent.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent(id = "a", name = "A组件")
public class ACmp extends NodeComponent {
@Override
public void process() {
System.out.println("ACmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.liteflowcomponent.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent(id = "b", name = "B组件")
public class BCmp extends NodeComponent {
@Override
public void process() {
System.out.println("BCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.liteflowcomponent.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent(id = "c", name = "C组件")
public class CCmp extends NodeComponent {
@Override
public void process() {
System.out.println("CCmp executed!");
}
}

View File

@@ -0,0 +1,21 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/4/1
*/
package com.yomahub.liteflow.test.liteflowcomponent.cmp;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
@LiteflowComponent("d")
public class DCmp extends NodeComponent {
@Override
public void process() {
System.out.println("DCmp executed!");
}
}

View File

@@ -0,0 +1 @@
liteflow.rule-source=liteflowComponent/flow.xml

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<flow>
<chain name="chain1">
<then value="a,b,chain2"/>
</chain>
<chain name="chain2">
<then value="c,b,a,d"/>
</chain>
</flow>