浏览代码

enhancement #I4EXCP 新增自定义关闭/启动 Banner

bryan31 3 年之前
父节点
当前提交
b703a13a42

+ 18 - 2
liteflow-core/src/main/java/com/yomahub/liteflow/property/LiteflowConfig.java

@@ -17,6 +17,7 @@ import com.sun.org.apache.xpath.internal.operations.Bool;
  * 这个类中的属性为什么不用基本类型,而用包装类型呢
  * 是因为这个类是springboot和spring的最终参数获取器,考虑到spring的场景,有些参数不是必须配置。基本类型就会出现默认值的情况。
  * 所以为了要有null值出现,这里采用包装类型
+ *
  * @author Bryan.Zhang
  */
 public class LiteflowConfig {
@@ -67,6 +68,9 @@ public class LiteflowConfig {
     //重试次数
     private Integer retryCount;
 
+    //是否打印liteflow banner
+    private Boolean printBanner;
+
     public Boolean getEnable() {
         if (ObjectUtil.isNull(enable)) {
             return true;
@@ -220,9 +224,9 @@ public class LiteflowConfig {
     }
 
     public String getZkNode() {
-        if (StrUtil.isBlank(zkNode)){
+        if (StrUtil.isBlank(zkNode)) {
             return "/lite-flow/flow";
-        }else{
+        } else {
             return zkNode;
         }
     }
@@ -230,4 +234,16 @@ public class LiteflowConfig {
     public void setZkNode(String zkNode) {
         this.zkNode = zkNode;
     }
+
+    public Boolean getPrintBanner() {
+        if (ObjectUtil.isNull(printBanner)) {
+            return Boolean.TRUE;
+        } else {
+            return printBanner;
+        }
+    }
+
+    public void setPrintBanner(Boolean printBanner) {
+        this.printBanner = printBanner;
+    }
 }

+ 13 - 2
liteflow-core/src/main/java/com/yomahub/liteflow/spring/ComponentScanner.java

@@ -10,6 +10,8 @@ package com.yomahub.liteflow.spring;
 
 import com.yomahub.liteflow.aop.ICmpAroundAspect;
 import com.yomahub.liteflow.core.NodeComponent;
+import com.yomahub.liteflow.property.LiteflowConfig;
+import com.yomahub.liteflow.property.LiteflowConfigGetter;
 import com.yomahub.liteflow.util.LOGOPrinter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,13 +30,22 @@ public class ComponentScanner implements BeanPostProcessor {
 
     public static Map<String, NodeComponent> nodeComponentMap = new HashMap<>();
 
+    private LiteflowConfig liteflowConfig;
+
     public static ICmpAroundAspect cmpAroundAspect;
 
-    static {
-        // 打印liteflow的LOGO
+    public ComponentScanner() {
         LOGOPrinter.print();
     }
 
+    public ComponentScanner(LiteflowConfig liteflowConfig) {
+        this.liteflowConfig = liteflowConfig;
+        if(liteflowConfig.getPrintBanner()){
+            // 打印liteflow的LOGO
+            LOGOPrinter.print();
+        }
+    }
+
     @Override
     public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
         return bean;

+ 11 - 0
liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/LiteflowProperty.java

@@ -41,6 +41,9 @@ public class LiteflowProperty {
     //重试次数
     private int retryCount;
 
+    //是否打印liteflow banner
+    private boolean printBanner;
+
     public boolean isEnable() {
         return enable;
     }
@@ -120,4 +123,12 @@ public class LiteflowProperty {
     public void setZkNode(String zkNode) {
         this.zkNode = zkNode;
     }
+
+    public boolean isPrintBanner() {
+        return printBanner;
+    }
+
+    public void setPrintBanner(boolean printBanner) {
+        this.printBanner = printBanner;
+    }
 }

+ 2 - 2
liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowMainAutoConfiguration.java

@@ -29,8 +29,8 @@ import org.springframework.context.annotation.Import;
 public class LiteflowMainAutoConfiguration {
 
     @Bean
-    public ComponentScanner componentScanner(){
-        return new ComponentScanner();
+    public ComponentScanner componentScanner(LiteflowConfig liteflowConfig){
+        return new ComponentScanner(liteflowConfig);
     }
 
     @Bean

+ 1 - 0
liteflow-spring-boot-starter/src/main/java/com/yomahub/liteflow/springboot/config/LiteflowPropertyAutoConfiguration.java

@@ -39,6 +39,7 @@ public class LiteflowPropertyAutoConfiguration {
         liteflowConfig.setSupportMultipleType(property.isSupportMultipleType());
         liteflowConfig.setRetryCount(property.getRetryCount());
         liteflowConfig.setZkNode(property.getZkNode());
+        liteflowConfig.setPrintBanner(property.isPrintBanner());
         return liteflowConfig;
     }
 }

+ 12 - 0
liteflow-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json

@@ -6,6 +6,12 @@
       "description": "Whether to turn on liteflow.",
       "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
     },
+    {
+      "name": "liteflow.print-banner",
+      "type": "java.lang.Boolean",
+      "description": "Whether to print liteflow banner.",
+      "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
+    },
     {
       "name": "liteflow.rule-source",
       "type": "java.lang.String",
@@ -18,6 +24,12 @@
       "description": "Set concurrent data slot size.",
       "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
     },
+    {
+      "name": "liteflow.zk-node",
+      "type": "java.lang.String",
+      "description": "Node definition for ZK configuration.",
+      "sourceType": "com.yomahub.liteflow.springboot.LiteflowProperty"
+    },
     {
       "name": "liteflow.when-max-wait-seconds",
       "type": "java.lang.Integer",

+ 2 - 1
liteflow-spring-boot-starter/src/main/resources/META-INF/liteflow-default.properties

@@ -1,4 +1,5 @@
 liteflow.enable=true
+liteflow.print-banner=true
 liteflow.rule-source=config/flow.xml
 liteflow.zk-node=/lite-flow/flow
 liteflow.slot-size=1024
@@ -11,4 +12,4 @@ liteflow.support-multiple-type=false
 liteflow.monitor.enable-log=false
 liteflow.monitor.queue-limit=200
 liteflow.monitor.delay=300000
-liteflow.monitor.period=300000
+liteflow.monitor.period=300000

+ 41 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/BannerPrintSpringbootTest.java

@@ -0,0 +1,41 @@
+package com.yomahub.liteflow.test.bannerPrint;
+
+import cn.hutool.core.io.resource.ResourceUtil;
+import com.yomahub.liteflow.core.FlowExecutor;
+import com.yomahub.liteflow.entity.data.DefaultSlot;
+import com.yomahub.liteflow.entity.data.LiteflowResponse;
+import com.yomahub.liteflow.enums.FlowParserTypeEnum;
+import com.yomahub.liteflow.flow.FlowBus;
+import com.yomahub.liteflow.test.BaseTest;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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;
+
+import javax.annotation.Resource;
+
+/**
+ * springboot环境下重新加载规则测试
+ * @author Bryan.Zhang
+ * @since 2.6.4
+ */
+@RunWith(SpringRunner.class)
+@TestPropertySource(value = "classpath:/bannerPrint/application.properties")
+@SpringBootTest(classes = BannerPrintSpringbootTest.class)
+@EnableAutoConfiguration
+@ComponentScan({"com.yomahub.liteflow.test.bannerPrint.cmp"})
+public class BannerPrintSpringbootTest extends BaseTest {
+
+    @Resource
+    private FlowExecutor flowExecutor;
+
+    @Test
+    public void testRefresh() throws Exception{
+        LiteflowResponse<DefaultSlot> response = flowExecutor.execute2Resp("chain1", "arg");
+        Assert.assertTrue(response.isSuccess());
+    }
+}

+ 20 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/ACmp.java

@@ -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.bannerPrint.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("a")
+public class ACmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("ACmp executed!");
+	}
+}

+ 21 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/BCmp.java

@@ -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.bannerPrint.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("b")
+public class BCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("BCmp executed!");
+	}
+
+}

+ 21 - 0
liteflow-testcase-springboot/src/test/java/com/yomahub/liteflow/test/bannerPrint/cmp/CCmp.java

@@ -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.bannerPrint.cmp;
+
+import com.yomahub.liteflow.core.NodeComponent;
+import org.springframework.stereotype.Component;
+
+@Component("c")
+public class CCmp extends NodeComponent {
+
+	@Override
+	public void process() {
+		System.out.println("CCmp executed!");
+	}
+
+}

+ 2 - 0
liteflow-testcase-springboot/src/test/resources/bannerPrint/application.properties

@@ -0,0 +1,2 @@
+liteflow.rule-source=bannerPrint/flow.xml
+liteflow.print-banner=true

+ 6 - 0
liteflow-testcase-springboot/src/test/resources/bannerPrint/flow.xml

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