From aa6a347d52c4c8fc55ebe4f982e75561ab2329e3 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 4 Dec 2017 14:27:07 +0800 Subject: [PATCH 01/42] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.bat | 1 + pom.xml | 29 +++++++++++++++++++ .../liteflow/core/FlowExecutor.java | 9 ++++-- .../liteflow/exception/FlowException.java | 21 ++++++++++++++ .../liteflow/test/TestWithSpringMain.java | 2 +- src/test/resources/{ => config}/flow.xml | 0 src/test/resources/spring-test.xml | 2 +- 7 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 deploy.bat create mode 100644 src/main/java/com/thebeastshop/liteflow/exception/FlowException.java rename src/test/resources/{ => config}/flow.xml (100%) diff --git a/deploy.bat b/deploy.bat new file mode 100644 index 000000000..c382c102f --- /dev/null +++ b/deploy.bat @@ -0,0 +1 @@ +mvn clean install deploy \ No newline at end of file diff --git a/pom.xml b/pom.xml index 27c0b52ba..cfbd990a3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ 3.4 4.1 2.4 + 1.2 4.2.6.RELEASE 1.7.21 1.2.17 @@ -49,6 +50,16 @@ spring-context ${spring.version} + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-expression + ${spring.version} + org.springframework spring-test @@ -84,6 +95,11 @@ junit ${junit.version} + + commons-logging + commons-logging + ${commons-logging.version} + @@ -107,4 +123,17 @@ + + + + nexus-releases + nexus-releases + http://118.178.236.200:8087/nexus/content/repositories/thirdparty + + + nexus-snapshots + nexus-snapshots + http://118.178.236.200:8087/nexus/content/repositories/snapshots + + \ No newline at end of file diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 708fce999..7ab5e7e56 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -23,6 +23,7 @@ import com.thebeastshop.liteflow.entity.config.Node; import com.thebeastshop.liteflow.entity.config.ThenCondition; import com.thebeastshop.liteflow.entity.config.WhenCondition; import com.thebeastshop.liteflow.entity.data.DataBus; +import com.thebeastshop.liteflow.exception.FlowException; import com.thebeastshop.liteflow.flow.FlowBus; import com.thebeastshop.liteflow.parser.FlowParser; @@ -78,13 +79,15 @@ public class FlowExecutor { if(component.isAccess()){ component.execute(); }else{ - LOG.info("component[{}] do not gain access",component.getClass().getSimpleName()); + LOG.error("component[{}] do not gain access",component.getClass().getSimpleName()); + throw new FlowException("component ["+component.getClass().getSimpleName()+"] do not gain access"); } }catch(Throwable t){ if(component.isContinueOnError()){ LOG.error("component[{}] cause error,but flow is still go on",t,component.getClass().getSimpleName()); }else{ - throw new Exception(t); + LOG.error(t.getMessage(),t); + throw t; } } } @@ -100,7 +103,7 @@ public class FlowExecutor { return DataBus.getSlot(slotIndex).getResponseData(); }catch(Exception e){ LOG.error("executor cause error",e); - return null; + throw new FlowException("executor cause error"); }finally{ DataBus.releaseSlot(slotIndex); } diff --git a/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java b/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java new file mode 100644 index 000000000..e3b1f5e3b --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class FlowException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public FlowException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java index 55de356f1..2a0c459ea 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java +++ b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java @@ -25,7 +25,7 @@ public class TestWithSpringMain { public void test1() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(10); - for(int i=0;i<100;i++){ + for(int i=0;i<1;i++){ executorService.submit(new Thread(){ @Override public void run() { diff --git a/src/test/resources/flow.xml b/src/test/resources/config/flow.xml similarity index 100% rename from src/test/resources/flow.xml rename to src/test/resources/config/flow.xml diff --git a/src/test/resources/spring-test.xml b/src/test/resources/spring-test.xml index 4caa5f00f..8cc2046d7 100644 --- a/src/test/resources/spring-test.xml +++ b/src/test/resources/spring-test.xml @@ -13,7 +13,7 @@ - flow.xml + config/flow.xml From 11e252e608e96c3ae8e8adea219fede2bc58c998 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 4 Dec 2017 14:56:33 +0800 Subject: [PATCH 02/42] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/core/FlowExecutor.java | 23 +++++++++++-------- .../exception/ChainNotFoundException.java | 21 +++++++++++++++++ .../ComponentNotAccessException.java | 21 +++++++++++++++++ .../FlowExecutorNotInitException.java | 21 +++++++++++++++++ ...xception.java => FlowSystemException.java} | 4 ++-- .../exception/NoAvailableSlotException.java | 21 +++++++++++++++++ 6 files changed, 100 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java create mode 100644 src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java create mode 100644 src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java rename src/main/java/com/thebeastshop/liteflow/exception/{FlowException.java => FlowSystemException.java} (73%) create mode 100644 src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 7ab5e7e56..49cb0ac93 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -9,6 +9,7 @@ */ package com.thebeastshop.liteflow.core; +import java.text.MessageFormat; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -23,7 +24,11 @@ import com.thebeastshop.liteflow.entity.config.Node; import com.thebeastshop.liteflow.entity.config.ThenCondition; import com.thebeastshop.liteflow.entity.config.WhenCondition; import com.thebeastshop.liteflow.entity.data.DataBus; -import com.thebeastshop.liteflow.exception.FlowException; +import com.thebeastshop.liteflow.exception.ChainNotFoundException; +import com.thebeastshop.liteflow.exception.ComponentNotAccessException; +import com.thebeastshop.liteflow.exception.FlowExecutorNotInitException; +import com.thebeastshop.liteflow.exception.FlowSystemException; +import com.thebeastshop.liteflow.exception.NoAvailableSlotException; import com.thebeastshop.liteflow.flow.FlowBus; import com.thebeastshop.liteflow.parser.FlowParser; @@ -38,7 +43,8 @@ public class FlowExecutor { try { FlowParser.parseLocal(path); } catch (Exception e) { - LOG.error("init flow executor cause error,cannot parse rule file{}", path, e); + String errorMsg = MessageFormat.format("init flow executor cause error,cannot parse rule file{}", path); + throw new FlowExecutorNotInitException(errorMsg); } } } @@ -53,13 +59,14 @@ public class FlowExecutor { Chain chain = FlowBus.getChain(chainId); if(chain == null){ - LOG.error("couldn't find chain with the id[{}]",chainId); + String errorMsg = MessageFormat.format("couldn't find chain with the id[{}]", chainId); + throw new ChainNotFoundException(errorMsg); } slotIndex = DataBus.offerSlot(); LOG.info("slot[{}] offered",slotIndex); if(slotIndex == -1){ - throw new Exception("there is no available slot"); + throw new NoAvailableSlotException("there is no available slot"); } DataBus.getSlot(slotIndex).setRequestData(param); @@ -79,14 +86,13 @@ public class FlowExecutor { if(component.isAccess()){ component.execute(); }else{ - LOG.error("component[{}] do not gain access",component.getClass().getSimpleName()); - throw new FlowException("component ["+component.getClass().getSimpleName()+"] do not gain access"); + String errorMsg = MessageFormat.format("component[{}] do not gain access", component.getClass().getSimpleName()); + throw new ComponentNotAccessException(errorMsg); } }catch(Throwable t){ if(component.isContinueOnError()){ LOG.error("component[{}] cause error,but flow is still go on",t,component.getClass().getSimpleName()); }else{ - LOG.error(t.getMessage(),t); throw t; } } @@ -102,8 +108,7 @@ public class FlowExecutor { DataBus.getSlot(slotIndex).printStep(); return DataBus.getSlot(slotIndex).getResponseData(); }catch(Exception e){ - LOG.error("executor cause error",e); - throw new FlowException("executor cause error"); + throw new FlowSystemException("executor cause error"); }finally{ DataBus.releaseSlot(slotIndex); } diff --git a/src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java b/src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java new file mode 100644 index 000000000..05ec01fb3 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/ChainNotFoundException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class ChainNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ChainNotFoundException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java b/src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java new file mode 100644 index 000000000..bcc118ee4 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/ComponentNotAccessException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class ComponentNotAccessException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public ComponentNotAccessException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java b/src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java new file mode 100644 index 000000000..40fb8d781 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/FlowExecutorNotInitException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class FlowExecutorNotInitException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public FlowExecutorNotInitException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java b/src/main/java/com/thebeastshop/liteflow/exception/FlowSystemException.java similarity index 73% rename from src/main/java/com/thebeastshop/liteflow/exception/FlowException.java rename to src/main/java/com/thebeastshop/liteflow/exception/FlowSystemException.java index e3b1f5e3b..6789c2c51 100644 --- a/src/main/java/com/thebeastshop/liteflow/exception/FlowException.java +++ b/src/main/java/com/thebeastshop/liteflow/exception/FlowSystemException.java @@ -1,13 +1,13 @@ package com.thebeastshop.liteflow.exception; -public class FlowException extends RuntimeException { +public class FlowSystemException extends RuntimeException { private static final long serialVersionUID = 1L; /** 异常信息 */ private String message; - public FlowException(String message) { + public FlowSystemException(String message) { this.message = message; } diff --git a/src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java b/src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java new file mode 100644 index 000000000..beda393da --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/exception/NoAvailableSlotException.java @@ -0,0 +1,21 @@ +package com.thebeastshop.liteflow.exception; + +public class NoAvailableSlotException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + /** 异常信息 */ + private String message; + + public NoAvailableSlotException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} From 233df6aaad8bef07a11ee80ce6c328c16d6ed265 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 4 Dec 2017 20:34:38 +0800 Subject: [PATCH 03/42] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89SLOT=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/core/FlowExecutor.java | 8 +- .../liteflow/core/NodeCondComponent.java | 9 +- .../liteflow/entity/data/DataBus.java | 17 +-- .../liteflow/entity/data/DefaultSlot.java | 100 ++++++++++++++++++ .../liteflow/entity/data/Slot.java | 92 +++------------- 5 files changed, 139 insertions(+), 87 deletions(-) create mode 100644 src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 49cb0ac93..e3723529a 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -24,6 +24,8 @@ import com.thebeastshop.liteflow.entity.config.Node; import com.thebeastshop.liteflow.entity.config.ThenCondition; import com.thebeastshop.liteflow.entity.config.WhenCondition; import com.thebeastshop.liteflow.entity.data.DataBus; +import com.thebeastshop.liteflow.entity.data.DefaultSlot; +import com.thebeastshop.liteflow.entity.data.Slot; import com.thebeastshop.liteflow.exception.ChainNotFoundException; import com.thebeastshop.liteflow.exception.ComponentNotAccessException; import com.thebeastshop.liteflow.exception.FlowExecutorNotInitException; @@ -54,6 +56,10 @@ public class FlowExecutor { } public T execute(String chainId,Object param){ + return execute(chainId, param, DefaultSlot.class); + } + + public T execute(String chainId,Object param,Class slotClazz){ int slotIndex = -1; try{ Chain chain = FlowBus.getChain(chainId); @@ -63,7 +69,7 @@ public class FlowExecutor { throw new ChainNotFoundException(errorMsg); } - slotIndex = DataBus.offerSlot(); + slotIndex = DataBus.offerSlot(slotClazz); LOG.info("slot[{}] offered",slotIndex); if(slotIndex == -1){ throw new NoAvailableSlotException("there is no available slot"); diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java index fa8472393..216fa4c90 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java @@ -1,10 +1,11 @@ /** - *

Title: litis

- *

Description: redis的全方位开发运维平台

+ *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

*

Copyright: Copyright (c) 2017

* @author Bryan.Zhang - * @email 47483522@qq.com - * @Date 2017-11-28 + * @email weenyc31@163.com + * @Date 2017-7-28 + * @version 1.0 */ package com.thebeastshop.liteflow.core; diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java index dbbebe441..203c8148f 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java @@ -24,13 +24,18 @@ public class DataBus { private static Slot[] slots = new Slot[SLOT_SIZE]; - public synchronized static int offerSlot(){ - for(int i = 0; i < slots.length; i++){ - if(slots[i] == null){ - slots[i] = new Slot(); - OCCUPY_COUNT.incrementAndGet(); - return i; + public synchronized static int offerSlot(Class slotClazz){ + try{ + for(int i = 0; i < slots.length; i++){ + if(slots[i] == null){ + slots[i] = slotClazz.newInstance(); + OCCUPY_COUNT.incrementAndGet(); + return i; + } } + }catch(Exception e){ + LOG.error("offer slot error",e); + return -1; } return -1; } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java new file mode 100644 index 000000000..4cab92f3e --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java @@ -0,0 +1,100 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-3 + * @version 1.0 + */ +package com.thebeastshop.liteflow.entity.data; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings("unchecked") +public class DefaultSlot implements Slot{ + + private static final Logger LOG = LoggerFactory.getLogger(Slot.class); + + private final String REQUEST = "request"; + + private final String RESPONSE = "response"; + + private final String COND_NODE_PREFIX = "cond_"; + + private final String NODE_INPUT_PREFIX = "input_"; + + private final String NODE_OUTPUT_PREFIX = "output_"; + + private List executeSteps = new ArrayList(); + + private ConcurrentHashMap dataMap = new ConcurrentHashMap(); + + public T getInput(String nodeId){ + return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId); + } + + public T getOutput(String nodeId){ + return (T)dataMap.get(NODE_OUTPUT_PREFIX + nodeId); + } + + public void setInput(String nodeId,T t){ + dataMap.put(NODE_INPUT_PREFIX + nodeId, t); + } + + public void setOutput(String nodeId,T t){ + dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t); + } + + public T getRequestData(){ + return (T)dataMap.get(REQUEST); + } + + public void setRequestData(T t){ + dataMap.put(REQUEST, t); + } + + public T getResponseData(){ + return (T)dataMap.get(RESPONSE); + } + + public void setResponseData(T t){ + dataMap.put(RESPONSE, t); + } + + public T getData(String key){ + return (T)dataMap.get(key); + } + + public void setData(String key, T t){ + dataMap.put(key, t); + } + + public void setCondResult(String key, T t){ + dataMap.put(COND_NODE_PREFIX + key, t); + } + + public T getCondResult(String key){ + return (T)dataMap.get(COND_NODE_PREFIX + key); + } + + public void addStep(String nodeId){ + this.executeSteps.add(nodeId); + } + + public void printStep(){ + StringBuffer str = new StringBuffer(); + for(int i = 0; i < this.executeSteps.size(); i++){ + str.append(executeSteps.get(i)); + if(i < this.executeSteps.size()-1){ + str.append("==>"); + } + } + LOG.info(str.toString()); + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java index ce2f3a965..c6e5ca159 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java @@ -4,97 +4,37 @@ *

Copyright: Copyright (c) 2017

* @author Bryan.Zhang * @email weenyc31@163.com - * @Date 2017-8-3 + * @Date 2017-12-4 * @version 1.0 */ package com.thebeastshop.liteflow.entity.data; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings("unchecked") -public class Slot { +public interface Slot { + public T getInput(String nodeId); - private static final Logger LOG = LoggerFactory.getLogger(Slot.class); + public T getOutput(String nodeId); - private final String REQUEST = "request"; + public void setInput(String nodeId,T t); - private final String RESPONSE = "response"; + public void setOutput(String nodeId,T t); - private final String COND_NODE_PREFIX = "cond_"; + public T getRequestData(); - private final String NODE_INPUT_PREFIX = "input_"; + public void setRequestData(T t); - private final String NODE_OUTPUT_PREFIX = "output_"; + public T getResponseData(); - private List executeSteps = new ArrayList(); + public void setResponseData(T t); - private ConcurrentHashMap dataMap = new ConcurrentHashMap(); + public T getData(String key); - public T getInput(String nodeId){ - return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId); - } + public void setData(String key, T t); - public T getOutput(String nodeId){ - return (T)dataMap.get(NODE_OUTPUT_PREFIX + nodeId); - } + public void setCondResult(String key, T t); - public void setInput(String nodeId,T t){ - dataMap.put(NODE_INPUT_PREFIX + nodeId, t); - } + public T getCondResult(String key); - public void setOutput(String nodeId,T t){ - dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t); - } + public void addStep(String nodeId); - public T getRequestData(){ - return (T)dataMap.get(REQUEST); - } - - public void setRequestData(T t){ - dataMap.put(REQUEST, t); - } - - public T getResponseData(){ - return (T)dataMap.get(RESPONSE); - } - - public void setResponseData(T t){ - dataMap.put(RESPONSE, t); - } - - public T getData(String key){ - return (T)dataMap.get(key); - } - - public void setData(String key, T t){ - dataMap.put(key, t); - } - - public void setCondResult(String key, T t){ - dataMap.put(COND_NODE_PREFIX + key, t); - } - - public T getCondResult(String key){ - return (T)dataMap.get(COND_NODE_PREFIX + key); - } - - public void addStep(String nodeId){ - this.executeSteps.add(nodeId); - } - - public void printStep(){ - StringBuffer str = new StringBuffer(); - for(int i = 0; i < this.executeSteps.size(); i++){ - str.append(executeSteps.get(i)); - if(i < this.executeSteps.size()-1){ - str.append("==>"); - } - } - LOG.info(str.toString()); - } + public void printStep(); } From 311c34a1b3f7a22f413c4af48acc61d84273a763 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 4 Dec 2017 20:35:03 +0800 Subject: [PATCH 04/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cfbd990a3..3c1ed2b7f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.1 + 1.2.2 UTF-8 From ede135b69304c291abdb539bbfb0b63e5b83ae45 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 5 Dec 2017 17:51:22 +0800 Subject: [PATCH 05/42] =?UTF-8?q?SLOT=E7=9A=84=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java index 4cab92f3e..83c4c8e69 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java @@ -33,7 +33,7 @@ public class DefaultSlot implements Slot{ private List executeSteps = new ArrayList(); - private ConcurrentHashMap dataMap = new ConcurrentHashMap(); + protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); public T getInput(String nodeId){ return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId); From ef7ce5c82bf817a94849d0b64575e9c734f5a632 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 5 Dec 2017 18:33:24 +0800 Subject: [PATCH 06/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/config/flow.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/resources/config/flow.xml b/src/test/resources/config/flow.xml index dfa1dc4bf..a911b2b33 100644 --- a/src/test/resources/config/flow.xml +++ b/src/test/resources/config/flow.xml @@ -13,13 +13,13 @@ - + - - + + From 4ade621092937387df8447e889bf976783e0fa81 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 5 Dec 2017 18:55:46 +0800 Subject: [PATCH 07/42] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/config/flow.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/config/flow.xml b/src/test/resources/config/flow.xml index a911b2b33..87fe28548 100644 --- a/src/test/resources/config/flow.xml +++ b/src/test/resources/config/flow.xml @@ -13,7 +13,7 @@ - + From 8cd161a580fcb83a05645d5b7766a559ef14aad4 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 6 Dec 2017 14:15:25 +0800 Subject: [PATCH 08/42] =?UTF-8?q?=E6=94=B9=E9=80=A0=E5=92=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96SLOT=E7=9A=84=E6=89=A9=E5=B1=95=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/core/FlowExecutor.java | 1 + .../liteflow/entity/data/AbsSlot.java | 100 ++++++++++++++++++ .../liteflow/entity/data/DefaultSlot.java | 90 +--------------- 3 files changed, 103 insertions(+), 88 deletions(-) create mode 100644 src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index e3723529a..60c42effc 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -25,6 +25,7 @@ import com.thebeastshop.liteflow.entity.config.ThenCondition; import com.thebeastshop.liteflow.entity.config.WhenCondition; import com.thebeastshop.liteflow.entity.data.DataBus; import com.thebeastshop.liteflow.entity.data.DefaultSlot; +import com.thebeastshop.liteflow.entity.data.AbsSlot; import com.thebeastshop.liteflow.entity.data.Slot; import com.thebeastshop.liteflow.exception.ChainNotFoundException; import com.thebeastshop.liteflow.exception.ComponentNotAccessException; diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java new file mode 100644 index 000000000..4ed0ff3ea --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -0,0 +1,100 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-3 + * @version 1.0 + */ +package com.thebeastshop.liteflow.entity.data; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@SuppressWarnings("unchecked") +public abstract class AbsSlot implements Slot{ + + private static final Logger LOG = LoggerFactory.getLogger(Slot.class); + + private final String REQUEST = "request"; + + private final String RESPONSE = "response"; + + private final String COND_NODE_PREFIX = "cond_"; + + private final String NODE_INPUT_PREFIX = "input_"; + + private final String NODE_OUTPUT_PREFIX = "output_"; + + private List executeSteps = new ArrayList(); + + protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); + + public T getInput(String nodeId){ + return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId); + } + + public T getOutput(String nodeId){ + return (T)dataMap.get(NODE_OUTPUT_PREFIX + nodeId); + } + + public void setInput(String nodeId,T t){ + dataMap.put(NODE_INPUT_PREFIX + nodeId, t); + } + + public void setOutput(String nodeId,T t){ + dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t); + } + + public T getRequestData(){ + return (T)dataMap.get(REQUEST); + } + + public void setRequestData(T t){ + dataMap.put(REQUEST, t); + } + + public T getResponseData(){ + return (T)dataMap.get(RESPONSE); + } + + public void setResponseData(T t){ + dataMap.put(RESPONSE, t); + } + + public T getData(String key){ + return (T)dataMap.get(key); + } + + public void setData(String key, T t){ + dataMap.put(key, t); + } + + public void setCondResult(String key, T t){ + dataMap.put(COND_NODE_PREFIX + key, t); + } + + public T getCondResult(String key){ + return (T)dataMap.get(COND_NODE_PREFIX + key); + } + + public void addStep(String nodeId){ + this.executeSteps.add(nodeId); + } + + public void printStep(){ + StringBuffer str = new StringBuffer(); + for(int i = 0; i < this.executeSteps.size(); i++){ + str.append(executeSteps.get(i)); + if(i < this.executeSteps.size()-1){ + str.append("==>"); + } + } + LOG.info(str.toString()); + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java index 83c4c8e69..2d30e8a10 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DefaultSlot.java @@ -4,97 +4,11 @@ *

Copyright: Copyright (c) 2017

* @author Bryan.Zhang * @email weenyc31@163.com - * @Date 2017-8-3 + * @Date 2017-12-4 * @version 1.0 */ package com.thebeastshop.liteflow.entity.data; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ConcurrentHashMap; +public class DefaultSlot extends AbsSlot { -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings("unchecked") -public class DefaultSlot implements Slot{ - - private static final Logger LOG = LoggerFactory.getLogger(Slot.class); - - private final String REQUEST = "request"; - - private final String RESPONSE = "response"; - - private final String COND_NODE_PREFIX = "cond_"; - - private final String NODE_INPUT_PREFIX = "input_"; - - private final String NODE_OUTPUT_PREFIX = "output_"; - - private List executeSteps = new ArrayList(); - - protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); - - public T getInput(String nodeId){ - return (T)dataMap.get(NODE_INPUT_PREFIX + nodeId); - } - - public T getOutput(String nodeId){ - return (T)dataMap.get(NODE_OUTPUT_PREFIX + nodeId); - } - - public void setInput(String nodeId,T t){ - dataMap.put(NODE_INPUT_PREFIX + nodeId, t); - } - - public void setOutput(String nodeId,T t){ - dataMap.put(NODE_OUTPUT_PREFIX + nodeId, t); - } - - public T getRequestData(){ - return (T)dataMap.get(REQUEST); - } - - public void setRequestData(T t){ - dataMap.put(REQUEST, t); - } - - public T getResponseData(){ - return (T)dataMap.get(RESPONSE); - } - - public void setResponseData(T t){ - dataMap.put(RESPONSE, t); - } - - public T getData(String key){ - return (T)dataMap.get(key); - } - - public void setData(String key, T t){ - dataMap.put(key, t); - } - - public void setCondResult(String key, T t){ - dataMap.put(COND_NODE_PREFIX + key, t); - } - - public T getCondResult(String key){ - return (T)dataMap.get(COND_NODE_PREFIX + key); - } - - public void addStep(String nodeId){ - this.executeSteps.add(nodeId); - } - - public void printStep(){ - StringBuffer str = new StringBuffer(); - for(int i = 0; i < this.executeSteps.size(); i++){ - str.append(executeSteps.get(i)); - if(i < this.executeSteps.size()-1){ - str.append("==>"); - } - } - LOG.info(str.toString()); - } } From f2b7601044f052b3d9e62e898fbe2c961cff910a Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 6 Dec 2017 14:28:19 +0800 Subject: [PATCH 09/42] =?UTF-8?q?=E4=BC=98=E5=8C=96SLOT=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/thebeastshop/liteflow/core/NodeComponent.java | 2 +- .../java/com/thebeastshop/liteflow/entity/data/DataBus.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index 781bf0c01..6a44ec9ec 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -86,7 +86,7 @@ public abstract class NodeComponent { return this; } - public Slot getSlot(){ + public T getSlot(){ return DataBus.getSlot(this.slotIndexTL.get()); } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java index 203c8148f..de9eb4a10 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java @@ -40,8 +40,9 @@ public class DataBus { return -1; } - public static Slot getSlot(int slotIndex){ - return slots[slotIndex]; + @SuppressWarnings("unchecked") + public static T getSlot(int slotIndex){ + return (T)slots[slotIndex]; } public static void releaseSlot(int slotIndex){ From ba8ac461cb20db03061749082d244d4007b6f58c Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Thu, 7 Dec 2017 14:04:06 +0800 Subject: [PATCH 10/42] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8A=82=E7=82=B9isEnd?= =?UTF-8?q?=E7=89=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../liteflow/core/FlowExecutor.java | 4 ++++ .../liteflow/core/NodeComponent.java | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 60c42effc..136b78bbf 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -92,6 +92,10 @@ public class FlowExecutor { component.setSlotIndex(slotIndex); if(component.isAccess()){ component.execute(); + if(component.isEnd()) { + LOG.info("component[{}] lead the chain to end",component.getClass().getSimpleName()); + break; + } }else{ String errorMsg = MessageFormat.format("component[{}] do not gain access", component.getClass().getSimpleName()); throw new ComponentNotAccessException(errorMsg); diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index 6a44ec9ec..ca07d8897 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -29,8 +29,6 @@ public abstract class NodeComponent { private String nodeId; - private boolean continueOnError; - public void execute() throws Exception{ StopWatch stopWatch = new StopWatch(); stopWatch.start(); @@ -69,16 +67,25 @@ public abstract class NodeComponent { protected abstract void process() throws Exception; + /** + * 是否进入该节点 + */ protected boolean isAccess(){ return true; } - public boolean isContinueOnError() { - return continueOnError; + /** + * 出错是否继续执行 + */ + protected boolean isContinueOnError() { + return false; } - - public void setContinueOnError(boolean continueOnError) { - this.continueOnError = continueOnError; + + /** + * 是否结束整个流程(不往下继续执行) + */ + protected boolean isEnd() { + return false; } public NodeComponent setSlotIndex(Integer slotIndex) { From 632e543928424c3f994238fe6b395bbb04e803ee Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Fri, 8 Dec 2017 17:05:31 +0800 Subject: [PATCH 11/42] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=86=85?= =?UTF-8?q?=E9=83=A8=E7=AD=96=E7=95=A5=E8=B0=83=E7=94=A8=E7=89=B9=E6=80=A7?= =?UTF-8?q?=20=E9=87=8D=E5=86=99=E4=BA=86=E8=8A=82=E7=82=B9=E6=AD=A5?= =?UTF-8?q?=E9=AA=A4=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../liteflow/core/FlowExecutor.java | 48 ++++++++++--- .../liteflow/core/NodeComponent.java | 9 ++- .../liteflow/entity/data/AbsSlot.java | 22 ++++-- .../liteflow/entity/data/CmpStep.java | 67 +++++++++++++++++++ .../liteflow/entity/data/CmpStepType.java | 14 ++++ .../liteflow/entity/data/Slot.java | 2 +- .../thebeastshop/liteflow/flow/FlowBus.java | 6 ++ .../liteflow/spring/ComponentScaner.java | 1 + .../thebeastshop/liteflow/test/TestMain.java | 2 +- .../liteflow/test/TestWithSpringMain.java | 16 ++++- .../liteflow/test/component/HComponent.java | 32 +++++++++ .../liteflow/test/component/M1Component.java | 30 +++++++++ .../liteflow/test/component/M2Component.java | 30 +++++++++ .../liteflow/test/component/MComponent.java | 32 +++++++++ src/test/resources/config/flow.xml | 8 ++- src/test/resources/spring-test.xml | 2 +- 17 files changed, 296 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/thebeastshop/liteflow/entity/data/CmpStep.java create mode 100644 src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/M1Component.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/M2Component.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java diff --git a/pom.xml b/pom.xml index 3c1ed2b7f..a38f32236 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.2 + 1.2.3 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 136b78bbf..f748eb789 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -46,7 +46,7 @@ public class FlowExecutor { try { FlowParser.parseLocal(path); } catch (Exception e) { - String errorMsg = MessageFormat.format("init flow executor cause error,cannot parse rule file{}", path); + String errorMsg = MessageFormat.format("init flow executor cause error,cannot parse rule file{0}", path); throw new FlowExecutorNotInitException(errorMsg); } } @@ -57,26 +57,47 @@ public class FlowExecutor { } public T execute(String chainId,Object param){ - return execute(chainId, param, DefaultSlot.class); + return execute(chainId, param, DefaultSlot.class,null,false); } public T execute(String chainId,Object param,Class slotClazz){ - int slotIndex = -1; + return execute(chainId, param, slotClazz,null,false); + } + + public T invoke(String chainId,Class slotClazz,Integer slotIndex){ + return execute(chainId,null, slotClazz,slotIndex,true); + } + + public T execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ try{ + if(FlowBus.needInit()) { + init(); + } + Chain chain = FlowBus.getChain(chainId); if(chain == null){ - String errorMsg = MessageFormat.format("couldn't find chain with the id[{}]", chainId); + String errorMsg = MessageFormat.format("couldn't find chain with the id[{0}]", chainId); throw new ChainNotFoundException(errorMsg); } - slotIndex = DataBus.offerSlot(slotClazz); - LOG.info("slot[{}] offered",slotIndex); + if(!isInnerChain && slotIndex == null) { + slotIndex = DataBus.offerSlot(slotClazz); + LOG.info("slot[{}] offered",slotIndex); + } + if(slotIndex == -1){ throw new NoAvailableSlotException("there is no available slot"); } - DataBus.getSlot(slotIndex).setRequestData(param); + Slot slot = DataBus.getSlot(slotIndex); + if(slot == null) { + throw new NoAvailableSlotException("the slot is not exist"); + } + + if(!isInnerChain && param != null) { + slot.setRequestData(param); + } List conditionList = chain.getConditionList(); @@ -97,7 +118,7 @@ public class FlowExecutor { break; } }else{ - String errorMsg = MessageFormat.format("component[{}] do not gain access", component.getClass().getSimpleName()); + String errorMsg = MessageFormat.format("component[{0}] do not gain access", component.getClass().getSimpleName()); throw new ComponentNotAccessException(errorMsg); } }catch(Throwable t){ @@ -116,12 +137,17 @@ public class FlowExecutor { latch.await(15, TimeUnit.SECONDS); } } - DataBus.getSlot(slotIndex).printStep(); - return DataBus.getSlot(slotIndex).getResponseData(); + if(!isInnerChain) { + slot.printStep(); + } + return slot.getResponseData(); }catch(Exception e){ + LOG.error("executor cause error",e); throw new FlowSystemException("executor cause error"); }finally{ - DataBus.releaseSlot(slotIndex); + if(!isInnerChain) { + DataBus.releaseSlot(slotIndex); + } } } diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index ca07d8897..a4552a299 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -15,6 +15,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.thebeastshop.liteflow.entity.config.Node; +import com.thebeastshop.liteflow.entity.data.CmpStep; +import com.thebeastshop.liteflow.entity.data.CmpStepType; import com.thebeastshop.liteflow.entity.data.DataBus; import com.thebeastshop.liteflow.entity.data.Slot; import com.thebeastshop.liteflow.entity.monitor.CompStatistics; @@ -30,6 +32,7 @@ public abstract class NodeComponent { private String nodeId; public void execute() throws Exception{ + this.getSlot().addStep(new CmpStep(nodeId, CmpStepType.START)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); long initm=Runtime.getRuntime().freeMemory(); @@ -39,7 +42,7 @@ public abstract class NodeComponent { long timeSpent = stopWatch.getTime(); long endm=Runtime.getRuntime().freeMemory(); - this.getSlot().addStep(nodeId); + this.getSlot().addStep(new CmpStep(nodeId, CmpStepType.END)); //性能统计 CompStatistics statistics = new CompStatistics(); @@ -93,6 +96,10 @@ public abstract class NodeComponent { return this; } + public Integer getSlotIndex() { + return this.slotIndexTL.get(); + } + public T getSlot(){ return DataBus.getSlot(this.slotIndexTL.get()); } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 4ed0ff3ea..417d81af5 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -9,7 +9,10 @@ */ package com.thebeastshop.liteflow.entity.data; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Deque; +import java.util.Iterator; import java.util.List; import java.util.concurrent.ConcurrentHashMap; @@ -31,7 +34,7 @@ public abstract class AbsSlot implements Slot{ private final String NODE_OUTPUT_PREFIX = "output_"; - private List executeSteps = new ArrayList(); + private Deque executeSteps = new ArrayDeque(); protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); @@ -83,15 +86,22 @@ public abstract class AbsSlot implements Slot{ return (T)dataMap.get(COND_NODE_PREFIX + key); } - public void addStep(String nodeId){ - this.executeSteps.add(nodeId); + public void addStep(CmpStep step){ + CmpStep lastStep = this.executeSteps.peekLast(); + if(lastStep != null && lastStep.equals(step)) { + lastStep.setStepType(CmpStepType.SINGLE); + }else { + this.executeSteps.add(step); + } } public void printStep(){ StringBuffer str = new StringBuffer(); - for(int i = 0; i < this.executeSteps.size(); i++){ - str.append(executeSteps.get(i)); - if(i < this.executeSteps.size()-1){ + CmpStep cmpStep = null; + for (Iterator it = executeSteps.iterator(); it.hasNext();) { + cmpStep = it.next(); + str.append(cmpStep); + if(it.hasNext()){ str.append("==>"); } } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStep.java b/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStep.java new file mode 100644 index 000000000..3076df018 --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStep.java @@ -0,0 +1,67 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-12-8 + * @version 1.0 + */ +package com.thebeastshop.liteflow.entity.data; + +import java.text.MessageFormat; + +public class CmpStep { + private String nodeId; + + private CmpStepType stepType; + + public CmpStep(String nodeId, CmpStepType stepType) { + this.nodeId = nodeId; + this.stepType = stepType; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public CmpStepType getStepType() { + return stepType; + } + + public void setStepType(CmpStepType stepType) { + this.stepType = stepType; + } + + @Override + public String toString() { + if(stepType.equals(CmpStepType.SINGLE)) { + return MessageFormat.format("{0}", nodeId); + }else { + return MessageFormat.format("{0}({1})", nodeId,stepType); + } + + + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + }else { + if(getClass() != obj.getClass()) { + return false; + }else { + if(((CmpStep)obj).getNodeId().equals(this.getNodeId())) { + return true; + }else { + return false; + } + } + } + } +} diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java b/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java new file mode 100644 index 000000000..ba40c63ea --- /dev/null +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java @@ -0,0 +1,14 @@ +/** + *

Title: beast-price

+ *

Description: 价格计算服务

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @Date 2017年12月8日 + */ +package com.thebeastshop.liteflow.entity.data; + +public enum CmpStepType { + START, + END, + SINGLE; +} diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java index c6e5ca159..c7556439f 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java @@ -34,7 +34,7 @@ public interface Slot { public T getCondResult(String key); - public void addStep(String nodeId); + public void addStep(CmpStep step); public void printStep(); } diff --git a/src/main/java/com/thebeastshop/liteflow/flow/FlowBus.java b/src/main/java/com/thebeastshop/liteflow/flow/FlowBus.java index 72e142429..d8130c33f 100644 --- a/src/main/java/com/thebeastshop/liteflow/flow/FlowBus.java +++ b/src/main/java/com/thebeastshop/liteflow/flow/FlowBus.java @@ -12,6 +12,8 @@ package com.thebeastshop.liteflow.flow; import java.util.HashMap; import java.util.Map; +import org.apache.commons.collections4.MapUtils; + import com.thebeastshop.liteflow.entity.config.Chain; public class FlowBus { @@ -31,4 +33,8 @@ public class FlowBus { } chainMap.put(name, chain); } + + public static boolean needInit() { + return MapUtils.isEmpty(chainMap); + } } diff --git a/src/main/java/com/thebeastshop/liteflow/spring/ComponentScaner.java b/src/main/java/com/thebeastshop/liteflow/spring/ComponentScaner.java index 1249e21cf..81c74891a 100644 --- a/src/main/java/com/thebeastshop/liteflow/spring/ComponentScaner.java +++ b/src/main/java/com/thebeastshop/liteflow/spring/ComponentScaner.java @@ -31,6 +31,7 @@ public class ComponentScaner implements BeanPostProcessor, PriorityOrdered { return Ordered.LOWEST_PRECEDENCE; } + @SuppressWarnings("rawtypes") @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { Class clazz = bean.getClass(); diff --git a/src/test/java/com/thebeastshop/liteflow/test/TestMain.java b/src/test/java/com/thebeastshop/liteflow/test/TestMain.java index 0406f66ae..eb1096cfe 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/TestMain.java +++ b/src/test/java/com/thebeastshop/liteflow/test/TestMain.java @@ -17,7 +17,7 @@ import com.thebeastshop.liteflow.parser.FlowParser; public class TestMain { public static void main(String[] args) throws Exception { final FlowExecutor executor = new FlowExecutor(); - executor.setRulePath(Arrays.asList(new String[]{"flow.xml"})); + executor.setRulePath(Arrays.asList(new String[]{"config/flow.xml"})); executor.init(); for(int i=0;i<1;i++){ diff --git a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java index 2a0c459ea..5b9e3560f 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java +++ b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java @@ -25,11 +25,11 @@ public class TestWithSpringMain { public void test1() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(10); - for(int i=0;i<1;i++){ + for(int i=0;i<10;i++){ executorService.submit(new Thread(){ @Override public void run() { - String response = flowExecutor.execute("chain2", "it's a request"); + String response = flowExecutor.execute("chain1", "it's a request"); System.out.println(response); } }); @@ -37,4 +37,16 @@ public class TestWithSpringMain { System.out.println("done!"); System.in.read(); } + + @Test + public void test2() throws Exception { + try { + String response = flowExecutor.execute("chain3", "it's a request"); + System.out.println(response); + System.in.read(); + }catch(Exception e) { + e.printStackTrace(); + } + + } } diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java new file mode 100644 index 000000000..f1ab7a653 --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java @@ -0,0 +1,32 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; +import com.thebeastshop.liteflow.entity.data.DefaultSlot; + +@Component("h") +public class HComponent extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() { + System.out.println("Hcomponent executed!"); + flowExecutor.invoke("strategy", DefaultSlot.class, this.getSlotIndex()); + } + +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/M1Component.java b/src/test/java/com/thebeastshop/liteflow/test/component/M1Component.java new file mode 100644 index 000000000..9efbb153f --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/M1Component.java @@ -0,0 +1,30 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; + +@Component("m1") +public class M1Component extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() { + System.out.println("m1 component executed!"); + } + +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/M2Component.java b/src/test/java/com/thebeastshop/liteflow/test/component/M2Component.java new file mode 100644 index 000000000..96a6bf906 --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/M2Component.java @@ -0,0 +1,30 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; + +@Component("m2") +public class M2Component extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() { + System.out.println("m2 component executed!"); + } + +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java new file mode 100644 index 000000000..d9267b908 --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java @@ -0,0 +1,32 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; +import com.thebeastshop.liteflow.core.NodeCondComponent; + +@Component("m") +public class MComponent extends NodeCondComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + protected String processCond() throws Exception { + System.out.println("m conponent executed"); + return "m1"; + } + +} diff --git a/src/test/resources/config/flow.xml b/src/test/resources/config/flow.xml index 87fe28548..d29fc2d61 100644 --- a/src/test/resources/config/flow.xml +++ b/src/test/resources/config/flow.xml @@ -24,8 +24,10 @@ - - - + + + + + \ No newline at end of file diff --git a/src/test/resources/spring-test.xml b/src/test/resources/spring-test.xml index 8cc2046d7..685098480 100644 --- a/src/test/resources/spring-test.xml +++ b/src/test/resources/spring-test.xml @@ -10,7 +10,7 @@ - + config/flow.xml From 98d7d2a924f52f2c3b8192643be3410a48031dc2 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Fri, 8 Dec 2017 17:32:27 +0800 Subject: [PATCH 12/42] =?UTF-8?q?=E5=B0=8F=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thebeastshop/liteflow/entity/data/CmpStepType.java | 8 +++++--- .../thebeastshop/liteflow/test/TestWithSpringMain.java | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java b/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java index ba40c63ea..29e3b0524 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/CmpStepType.java @@ -1,9 +1,11 @@ /** - *

Title: beast-price

- *

Description: 价格计算服务

+ *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

*

Copyright: Copyright (c) 2017

* @author Bryan.Zhang - * @Date 2017年12月8日 + * @email weenyc31@163.com + * @Date 2017-12-8 + * @version 1.0 */ package com.thebeastshop.liteflow.entity.data; diff --git a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java index 5b9e3560f..95bf2a08e 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java +++ b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java @@ -25,7 +25,7 @@ public class TestWithSpringMain { public void test1() throws Exception { ExecutorService executorService = Executors.newFixedThreadPool(10); - for(int i=0;i<10;i++){ + for(int i=0;i<1;i++){ executorService.submit(new Thread(){ @Override public void run() { From eefbe197d8d31adb5f9c7769d1987178eaf03ce3 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 13 Dec 2017 19:42:39 +0800 Subject: [PATCH 13/42] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E6=89=A7=E8=A1=8C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index a4552a299..e5cf999dc 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -32,6 +32,7 @@ public abstract class NodeComponent { private String nodeId; public void execute() throws Exception{ + LOG.info("start component[{}] execution",this.getClass().getSimpleName()); this.getSlot().addStep(new CmpStep(nodeId, CmpStepType.START)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); From 809b0634257fe058ba00f2466b352d405ce3baf7 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 18 Dec 2017 20:25:13 +0800 Subject: [PATCH 14/42] =?UTF-8?q?=E7=AD=96=E7=95=A5=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=AD=96=E7=95=A5=E8=B0=83=E7=94=A8=E7=9A=84=E6=97=A0=E7=BA=A7?= =?UTF-8?q?=E5=B5=8C=E5=A5=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../liteflow/core/FlowExecutor.java | 8 ++-- .../liteflow/entity/data/AbsSlot.java | 10 +++++ .../liteflow/entity/data/Slot.java | 4 ++ .../liteflow/test/component/HComponent.java | 2 +- .../liteflow/test/component/M3Component.java | 32 ++++++++++++++++ .../liteflow/test/component/MComponent.java | 10 ++++- .../liteflow/test/component/P1Component.java | 30 +++++++++++++++ .../liteflow/test/component/P2Component.java | 30 +++++++++++++++ .../liteflow/test/component/PComponent.java | 37 +++++++++++++++++++ src/test/resources/config/flow.xml | 8 +++- 11 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/M3Component.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/P1Component.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/P2Component.java create mode 100644 src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java diff --git a/pom.xml b/pom.xml index a38f32236..821147328 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.3 + 1.2.4 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index f748eb789..f9ab60a79 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -64,8 +64,8 @@ public class FlowExecutor { return execute(chainId, param, slotClazz,null,false); } - public T invoke(String chainId,Class slotClazz,Integer slotIndex){ - return execute(chainId,null, slotClazz,slotIndex,true); + public void invoke(String chainId,Object param,Class slotClazz,Integer slotIndex){ + execute(chainId, param, slotClazz,slotIndex,true); } public T execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ @@ -95,8 +95,10 @@ public class FlowExecutor { throw new NoAvailableSlotException("the slot is not exist"); } - if(!isInnerChain && param != null) { + if(!isInnerChain) { slot.setRequestData(param); + }else { + slot.setChainReqData(chainId, param); } List conditionList = chain.getConditionList(); diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 417d81af5..32a695b88 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -34,6 +34,8 @@ public abstract class AbsSlot implements Slot{ private final String NODE_OUTPUT_PREFIX = "output_"; + private final String CHAIN_REQ_PREFIX = "chain_req_"; + private Deque executeSteps = new ArrayDeque(); protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); @@ -70,6 +72,14 @@ public abstract class AbsSlot implements Slot{ dataMap.put(RESPONSE, t); } + public T getChainReqData(String chainId) { + return (T)dataMap.get(CHAIN_REQ_PREFIX + chainId); + } + + public void setChainReqData(String chainId, T t) { + dataMap.put(CHAIN_REQ_PREFIX + chainId, t); + } + public T getData(String key){ return (T)dataMap.get(key); } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java index c7556439f..3e0d706f8 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java @@ -24,6 +24,10 @@ public interface Slot { public T getResponseData(); + public void setChainReqData(String chainId, T t); + + public T getChainReqData(String chainId); + public void setResponseData(T t); public T getData(String key); diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java index f1ab7a653..a58eb4448 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java +++ b/src/test/java/com/thebeastshop/liteflow/test/component/HComponent.java @@ -26,7 +26,7 @@ public class HComponent extends NodeComponent { @Override public void process() { System.out.println("Hcomponent executed!"); - flowExecutor.invoke("strategy", DefaultSlot.class, this.getSlotIndex()); + flowExecutor.invoke("strategy1",3, DefaultSlot.class, this.getSlotIndex()); } } diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/M3Component.java b/src/test/java/com/thebeastshop/liteflow/test/component/M3Component.java new file mode 100644 index 000000000..13926b7ce --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/M3Component.java @@ -0,0 +1,32 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; +import com.thebeastshop.liteflow.entity.data.DefaultSlot; + +@Component("m3") +public class M3Component extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() { + System.out.println("m3 component executed!"); + flowExecutor.invoke("strategy2",10, DefaultSlot.class, this.getSlotIndex()); + } + +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java index d9267b908..8e182c2ff 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java +++ b/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java @@ -26,7 +26,15 @@ public class MComponent extends NodeCondComponent { @Override protected String processCond() throws Exception { System.out.println("m conponent executed"); - return "m1"; + Integer flag = this.getSlot().getChainReqData("strategy1"); + if(flag == 1) { + return "m1"; + }else if(flag == 2){ + return "m2"; + }else { + return "m3"; + } + } } diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/P1Component.java b/src/test/java/com/thebeastshop/liteflow/test/component/P1Component.java new file mode 100644 index 000000000..c0f1a0c00 --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/P1Component.java @@ -0,0 +1,30 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; + +@Component("p1") +public class P1Component extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() { + System.out.println("p1 component executed!"); + } + +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/P2Component.java b/src/test/java/com/thebeastshop/liteflow/test/component/P2Component.java new file mode 100644 index 000000000..d60947c16 --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/P2Component.java @@ -0,0 +1,30 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; + +@Component("p2") +public class P2Component extends NodeComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + public void process() { + System.out.println("p2 component executed!"); + } + +} diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java new file mode 100644 index 000000000..f3f843bda --- /dev/null +++ b/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java @@ -0,0 +1,37 @@ +/** + *

Title: liteFlow

+ *

Description: 轻量级的组件式流程框架

+ *

Copyright: Copyright (c) 2017

+ * @author Bryan.Zhang + * @email weenyc31@163.com + * @Date 2017-8-1 + * @version 1.0 + */ +package com.thebeastshop.liteflow.test.component; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Component; + +import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeCondComponent; + +@Component("p") +public class PComponent extends NodeCondComponent { + + @Resource + private FlowExecutor flowExecutor; + + @Override + protected String processCond() throws Exception { + System.out.println("p conponent executed"); + Integer flag = this.getSlot().getChainReqData("strategy2"); + if(flag == 10) { + return "p1"; + }else { + return "p2"; + } + + } + +} diff --git a/src/test/resources/config/flow.xml b/src/test/resources/config/flow.xml index d29fc2d61..25f111ce6 100644 --- a/src/test/resources/config/flow.xml +++ b/src/test/resources/config/flow.xml @@ -27,7 +27,11 @@ - - + + + + + + \ No newline at end of file From 637b0db1a0ad775ecc3d31d5a30645bb5933a3fa Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Thu, 28 Dec 2017 15:04:09 +0800 Subject: [PATCH 15/42] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E7=B1=BB=E5=9E=8B=E6=94=B9=E6=88=90?= =?UTF-8?q?=E8=8A=82=E7=82=B9class=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/thebeastshop/liteflow/core/FlowExecutor.java | 10 ++++------ .../thebeastshop/liteflow/core/NodeCondComponent.java | 8 ++++++-- .../java/com/thebeastshop/liteflow/test/TestMain.java | 6 +++--- .../thebeastshop/liteflow/test/TestWithSpringMain.java | 9 +++++---- .../liteflow/test/component/BComponent.java | 3 --- .../liteflow/test/component/CondComponent.java | 5 +++-- .../liteflow/test/component/MComponent.java | 8 ++++---- .../liteflow/test/component/PComponent.java | 7 ++++--- 9 files changed, 30 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index 821147328..677d06277 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.4 + 1.2.5 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index f9ab60a79..cb653d906 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -14,7 +14,6 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,7 +24,6 @@ import com.thebeastshop.liteflow.entity.config.ThenCondition; import com.thebeastshop.liteflow.entity.config.WhenCondition; import com.thebeastshop.liteflow.entity.data.DataBus; import com.thebeastshop.liteflow.entity.data.DefaultSlot; -import com.thebeastshop.liteflow.entity.data.AbsSlot; import com.thebeastshop.liteflow.entity.data.Slot; import com.thebeastshop.liteflow.exception.ChainNotFoundException; import com.thebeastshop.liteflow.exception.ComponentNotAccessException; @@ -56,11 +54,11 @@ public class FlowExecutor { init(); } - public T execute(String chainId,Object param){ + public Slot execute(String chainId,Object param){ return execute(chainId, param, DefaultSlot.class,null,false); } - public T execute(String chainId,Object param,Class slotClazz){ + public Slot execute(String chainId,Object param,Class slotClazz){ return execute(chainId, param, slotClazz,null,false); } @@ -68,7 +66,7 @@ public class FlowExecutor { execute(chainId, param, slotClazz,slotIndex,true); } - public T execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ + public Slot execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ try{ if(FlowBus.needInit()) { init(); @@ -142,7 +140,7 @@ public class FlowExecutor { if(!isInnerChain) { slot.printStep(); } - return slot.getResponseData(); + return slot; }catch(Exception e){ LOG.error("executor cause error",e); throw new FlowSystemException("executor cause error"); diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java index 216fa4c90..d91b7658d 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeCondComponent.java @@ -9,14 +9,18 @@ */ package com.thebeastshop.liteflow.core; +import org.springframework.stereotype.Component; + public abstract class NodeCondComponent extends NodeComponent { @Override protected void process() throws Exception { - String nodeId = this.processCond(); + Class clazz = this.processCond(); + Component component = clazz.getAnnotation(Component.class); + String nodeId = component.value(); this.getSlot().setCondResult(this.getClass().getName(), nodeId); } - protected abstract String processCond() throws Exception; + protected abstract Class processCond() throws Exception; } diff --git a/src/test/java/com/thebeastshop/liteflow/test/TestMain.java b/src/test/java/com/thebeastshop/liteflow/test/TestMain.java index eb1096cfe..acf21a16d 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/TestMain.java +++ b/src/test/java/com/thebeastshop/liteflow/test/TestMain.java @@ -12,7 +12,7 @@ package com.thebeastshop.liteflow.test; import java.util.Arrays; import com.thebeastshop.liteflow.core.FlowExecutor; -import com.thebeastshop.liteflow.parser.FlowParser; +import com.thebeastshop.liteflow.entity.data.Slot; public class TestMain { public static void main(String[] args) throws Exception { @@ -21,8 +21,8 @@ public class TestMain { executor.init(); for(int i=0;i<1;i++){ - String response = executor.execute("chain1", "it's a request"); - System.out.println(response); + Slot slot = executor.execute("chain1", "it's a request"); + System.out.println(slot); } diff --git a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java index 95bf2a08e..a5e7f777e 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java +++ b/src/test/java/com/thebeastshop/liteflow/test/TestWithSpringMain.java @@ -11,6 +11,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.entity.data.Slot; @@ -29,8 +30,8 @@ public class TestWithSpringMain { executorService.submit(new Thread(){ @Override public void run() { - String response = flowExecutor.execute("chain1", "it's a request"); - System.out.println(response); + Slot slot = flowExecutor.execute("chain1", "it's a request"); + System.out.println(slot); } }); } @@ -41,8 +42,8 @@ public class TestWithSpringMain { @Test public void test2() throws Exception { try { - String response = flowExecutor.execute("chain3", "it's a request"); - System.out.println(response); + Slot slot = flowExecutor.execute("chain3", "it's a request"); + System.out.println(slot); System.in.read(); }catch(Exception e) { e.printStackTrace(); diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/BComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/BComponent.java index cac3113eb..be2b80c74 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/component/BComponent.java +++ b/src/test/java/com/thebeastshop/liteflow/test/component/BComponent.java @@ -9,9 +9,6 @@ */ package com.thebeastshop.liteflow.test.component; -import java.util.ArrayList; -import java.util.List; - import org.springframework.stereotype.Component; import com.thebeastshop.liteflow.core.NodeComponent; diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/CondComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/CondComponent.java index e742cf2db..1b39b1cf0 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/component/CondComponent.java +++ b/src/test/java/com/thebeastshop/liteflow/test/component/CondComponent.java @@ -10,13 +10,14 @@ package com.thebeastshop.liteflow.test.component; import org.springframework.stereotype.Component; +import com.thebeastshop.liteflow.core.NodeComponent; import com.thebeastshop.liteflow.core.NodeCondComponent; @Component("cond") public class CondComponent extends NodeCondComponent { @Override - protected String processCond() throws Exception { - return "b"; + protected Class processCond() throws Exception { + return BComponent.class; } } diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java index 8e182c2ff..4846a4730 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java +++ b/src/test/java/com/thebeastshop/liteflow/test/component/MComponent.java @@ -24,15 +24,15 @@ public class MComponent extends NodeCondComponent { private FlowExecutor flowExecutor; @Override - protected String processCond() throws Exception { + protected Class processCond() throws Exception { System.out.println("m conponent executed"); Integer flag = this.getSlot().getChainReqData("strategy1"); if(flag == 1) { - return "m1"; + return M1Component.class; }else if(flag == 2){ - return "m2"; + return M2Component.class; }else { - return "m3"; + return M3Component.class; } } diff --git a/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java b/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java index f3f843bda..d4f962bff 100644 --- a/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java +++ b/src/test/java/com/thebeastshop/liteflow/test/component/PComponent.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.thebeastshop.liteflow.core.FlowExecutor; +import com.thebeastshop.liteflow.core.NodeComponent; import com.thebeastshop.liteflow.core.NodeCondComponent; @Component("p") @@ -23,13 +24,13 @@ public class PComponent extends NodeCondComponent { private FlowExecutor flowExecutor; @Override - protected String processCond() throws Exception { + protected Class processCond() throws Exception { System.out.println("p conponent executed"); Integer flag = this.getSlot().getChainReqData("strategy2"); if(flag == 10) { - return "p1"; + return P1Component.class; }else { - return "p2"; + return P2Component.class; } } From 58b9f479b3839f36fbee3ad2adb32771599ffb70 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 2 Jan 2018 11:32:52 +0800 Subject: [PATCH 16/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dxml=E8=A1=A8=E8=BE=BE?= =?UTF-8?q?=E5=BC=8F=E9=87=8C=E6=9C=89=E7=A9=BA=E6=A0=BC=E5=B0=B1=E4=BC=9A?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=87=BA=E5=BC=82=E5=B8=B8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/thebeastshop/liteflow/parser/FlowParser.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java b/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java index 3fc4fb187..ef3aa4804 100644 --- a/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java +++ b/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java @@ -109,7 +109,7 @@ public class FlowParser { RegexEntity regexEntity = null; Node node = null; for (int i = 0; i < condArray.length; i++) { - regexEntity = parseNodeStr(condArray[i]); + regexEntity = parseNodeStr(condArray[i].trim()); node = nodeMap.get(regexEntity.getCondNode()); chainNodeList.add(node); if(regexEntity.getRealNodeArray() != null){ @@ -176,14 +176,18 @@ public class FlowParser { list.add(m.group()); } RegexEntity regexEntity = new RegexEntity(); - regexEntity.setCondNode(list.get(0)); + regexEntity.setCondNode(list.get(0).trim()); if(list.size() > 1){ - regexEntity.setRealNodeArray(list.get(1).split("\\|")); + String[] realNodeArray = list.get(1).split("\\|"); + for (int i = 0; i < realNodeArray.length; i++) { + realNodeArray[i] = realNodeArray[i].trim(); + } + regexEntity.setRealNodeArray(realNodeArray); } return regexEntity; } public static void main(String[] args) { - System.out.println(parseNodeStr("aaaa(bbb(xxxx|yyyy)|yyyy)")); + System.out.println(parseNodeStr("aaaa ( xxxx | yyyy | vvvv )")); } } From 3a49b8128130e1c1a62fe9080186cf249b47b06c Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 2 Jan 2018 11:33:37 +0800 Subject: [PATCH 17/42] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=B0=8F=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 677d06277..6292582d2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.5 + 1.2.6 UTF-8 From 014666e710909265d26d6b3aabbcfcdd7fb35e5e Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Fri, 5 Jan 2018 16:22:45 +0800 Subject: [PATCH 18/42] =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=99=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81slot=E7=9A=84=E6=B3=9B=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index cb653d906..4abd42bde 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -54,11 +54,11 @@ public class FlowExecutor { init(); } - public Slot execute(String chainId,Object param){ + public T execute(String chainId,Object param){ return execute(chainId, param, DefaultSlot.class,null,false); } - public Slot execute(String chainId,Object param,Class slotClazz){ + public T execute(String chainId,Object param,Class slotClazz){ return execute(chainId, param, slotClazz,null,false); } @@ -66,7 +66,7 @@ public class FlowExecutor { execute(chainId, param, slotClazz,slotIndex,true); } - public Slot execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ + public T execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ try{ if(FlowBus.needInit()) { init(); @@ -140,7 +140,7 @@ public class FlowExecutor { if(!isInnerChain) { slot.printStep(); } - return slot; + return (T)slot; }catch(Exception e){ LOG.error("executor cause error",e); throw new FlowSystemException("executor cause error"); From cfe6b344c11ebada708e5ca03acd9016d7a7ea38 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Fri, 5 Jan 2018 17:59:29 +0800 Subject: [PATCH 19/42] =?UTF-8?q?=E6=9B=B4=E6=94=B9monitor=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E9=97=B4=E9=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6292582d2..38992f585 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.6 + 1.2.7 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java index 37007d587..9c7e06808 100644 --- a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java +++ b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java @@ -39,7 +39,7 @@ public class MonitorBus { public void run() { MonitorBus.printStatistics(); } - }, 30*1000L, 1*60*1000L); + }, 5*60*1000L, 5*60*1000L); } public static void addStatistics(CompStatistics statistics){ From 2e90ea7a81e8d1469dc05848639ff0377e81100f Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Fri, 5 Jan 2018 19:25:06 +0800 Subject: [PATCH 20/42] =?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=B8=AD=E6=97=A5=E5=BF=97=E7=9A=84=E5=A2=9E=E8=A1=A5=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 7 +++---- .../com/thebeastshop/liteflow/entity/data/DataBus.java | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 4abd42bde..d86914817 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -67,6 +67,7 @@ public class FlowExecutor { } public T execute(String chainId,Object param,Class slotClazz,Integer slotIndex,boolean isInnerChain){ + Slot slot = null; try{ if(FlowBus.needInit()) { init(); @@ -88,7 +89,7 @@ public class FlowExecutor { throw new NoAvailableSlotException("there is no available slot"); } - Slot slot = DataBus.getSlot(slotIndex); + slot = DataBus.getSlot(slotIndex); if(slot == null) { throw new NoAvailableSlotException("the slot is not exist"); } @@ -137,15 +138,13 @@ public class FlowExecutor { latch.await(15, TimeUnit.SECONDS); } } - if(!isInnerChain) { - slot.printStep(); - } return (T)slot; }catch(Exception e){ LOG.error("executor cause error",e); throw new FlowSystemException("executor cause error"); }finally{ if(!isInnerChain) { + slot.printStep(); DataBus.releaseSlot(slotIndex); } } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java index de9eb4a10..dceac9c16 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java @@ -49,6 +49,7 @@ public class DataBus { if(slots[slotIndex] != null){ slots[slotIndex] = null; OCCUPY_COUNT.decrementAndGet(); + LOG.info("the slot[{}] released",slotIndex); }else{ LOG.warn("the slot[{}] has been released",slotIndex); } From 36acacefbd134fb2025ef39f56d0bfb45169f715 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 8 Jan 2018 17:25:13 +0800 Subject: [PATCH 21/42] =?UTF-8?q?isAccess=E6=96=B9=E6=B3=95=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E5=A6=82=E6=9E=9C=E4=B8=BAfalse=E5=88=99=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E5=BD=93=E5=89=8D=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 3 --- .../java/com/thebeastshop/liteflow/entity/data/DataBus.java | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 38992f585..01f053e05 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.7 + 1.2.8 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index d86914817..72a3a031e 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -118,9 +118,6 @@ public class FlowExecutor { LOG.info("component[{}] lead the chain to end",component.getClass().getSimpleName()); break; } - }else{ - String errorMsg = MessageFormat.format("component[{0}] do not gain access", component.getClass().getSimpleName()); - throw new ComponentNotAccessException(errorMsg); } }catch(Throwable t){ if(component.isContinueOnError()){ diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java index dceac9c16..9cd3b52fa 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java @@ -49,9 +49,9 @@ public class DataBus { if(slots[slotIndex] != null){ slots[slotIndex] = null; OCCUPY_COUNT.decrementAndGet(); - LOG.info("the slot[{}] released",slotIndex); + LOG.info("slot[{}] released",slotIndex); }else{ - LOG.warn("the slot[{}] has been released",slotIndex); + LOG.warn("slot[{}] already has been released",slotIndex); } } } From 5ce3b049ed8bc3594f60b4567fa8d712495137bd Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 10 Jan 2018 14:08:47 +0800 Subject: [PATCH 22/42] =?UTF-8?q?slot=E5=A2=9E=E5=8A=A0=E4=BA=86requestId?= =?UTF-8?q?=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/thebeastshop/liteflow/core/FlowExecutor.java | 5 +++++ .../thebeastshop/liteflow/entity/data/AbsSlot.java | 12 ++++++++++++ .../com/thebeastshop/liteflow/entity/data/Slot.java | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 01f053e05..0ede7c5e0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.8 + 1.2.9 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 72a3a031e..a10e217b8 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -14,6 +14,7 @@ import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,6 +95,10 @@ public class FlowExecutor { throw new NoAvailableSlotException("the slot is not exist"); } + if(StringUtils.isBlank(slot.getRequestId())) { + slot.generateRequestId(); + } + if(!isInnerChain) { slot.setRequestData(param); }else { diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 32a695b88..cb471e792 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -36,6 +36,8 @@ public abstract class AbsSlot implements Slot{ private final String CHAIN_REQ_PREFIX = "chain_req_"; + private final String REQUEST_ID = "req_id"; + private Deque executeSteps = new ArrayDeque(); protected ConcurrentHashMap dataMap = new ConcurrentHashMap(); @@ -117,4 +119,14 @@ public abstract class AbsSlot implements Slot{ } LOG.info(str.toString()); } + + @Override + public void generateRequestId() { + dataMap.put(REQUEST_ID, System.nanoTime()); + } + + @Override + public String getRequestId() { + return (String)dataMap.get(REQUEST_ID); + } } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java index 3e0d706f8..a7163e9a2 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java @@ -41,4 +41,8 @@ public interface Slot { public void addStep(CmpStep step); public void printStep(); + + public void generateRequestId(); + + public String getRequestId(); } From 958a1dc7a52c22d1c56c37ba85eef29e41575428 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 10 Jan 2018 14:15:58 +0800 Subject: [PATCH 23/42] fix requestId bug --- .../java/com/thebeastshop/liteflow/entity/data/AbsSlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index cb471e792..361593a71 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -122,7 +122,7 @@ public abstract class AbsSlot implements Slot{ @Override public void generateRequestId() { - dataMap.put(REQUEST_ID, System.nanoTime()); + dataMap.put(REQUEST_ID, new Long(System.nanoTime()).toString()); } @Override From 42257ed6915ae8e4ea9306a656267d86f9e6745b Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 10 Jan 2018 15:26:14 +0800 Subject: [PATCH 24/42] =?UTF-8?q?=E5=A2=9E=E5=8A=A0requestId=E8=BF=BD?= =?UTF-8?q?=E8=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/thebeastshop/liteflow/core/FlowExecutor.java | 7 ++++--- .../com/thebeastshop/liteflow/core/NodeComponent.java | 11 ++++++----- .../thebeastshop/liteflow/entity/data/DataBus.java | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index a10e217b8..1eabad407 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -97,6 +97,7 @@ public class FlowExecutor { if(StringUtils.isBlank(slot.getRequestId())) { slot.generateRequestId(); + LOG.info("requestId[{}] has generated",slot.getRequestId()); } if(!isInnerChain) { @@ -120,13 +121,13 @@ public class FlowExecutor { if(component.isAccess()){ component.execute(); if(component.isEnd()) { - LOG.info("component[{}] lead the chain to end",component.getClass().getSimpleName()); + LOG.info("[{}]:component[{}] lead the chain to end",slot.getRequestId(),component.getClass().getSimpleName()); break; } } }catch(Throwable t){ if(component.isContinueOnError()){ - LOG.error("component[{}] cause error,but flow is still go on",t,component.getClass().getSimpleName()); + LOG.error("[{}]:component[{}] cause error,but flow is still go on",t,slot.getRequestId(),component.getClass().getSimpleName()); }else{ throw t; } @@ -142,7 +143,7 @@ public class FlowExecutor { } return (T)slot; }catch(Exception e){ - LOG.error("executor cause error",e); + LOG.error("[{}]:executor cause error",e,slot.getRequestId()); throw new FlowSystemException("executor cause error"); }finally{ if(!isInnerChain) { diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index e5cf999dc..87b3dd63f 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -32,8 +32,9 @@ public abstract class NodeComponent { private String nodeId; public void execute() throws Exception{ - LOG.info("start component[{}] execution",this.getClass().getSimpleName()); - this.getSlot().addStep(new CmpStep(nodeId, CmpStepType.START)); + Slot slot = this.getSlot(); + LOG.info("[{}]:start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName()); + slot.addStep(new CmpStep(nodeId, CmpStepType.START)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); long initm=Runtime.getRuntime().freeMemory(); @@ -43,7 +44,7 @@ public abstract class NodeComponent { long timeSpent = stopWatch.getTime(); long endm=Runtime.getRuntime().freeMemory(); - this.getSlot().addStep(new CmpStep(nodeId, CmpStepType.END)); + slot.addStep(new CmpStep(nodeId, CmpStepType.END)); //性能统计 CompStatistics statistics = new CompStatistics(); @@ -54,7 +55,7 @@ public abstract class NodeComponent { if(this instanceof NodeCondComponent){ - String condNodeId = this.getSlot().getCondResult(this.getClass().getName()); + String condNodeId = slot.getCondResult(this.getClass().getName()); if(StringUtils.isNotBlank(condNodeId)){ Node thisNode = FlowParser.getNode(nodeId); Node condNode = thisNode.getCondNode(condNodeId); @@ -66,7 +67,7 @@ public abstract class NodeComponent { } } - LOG.debug("componnet[{}] finished in {} milliseconds",this.getClass().getSimpleName(),timeSpent); + LOG.debug("[{}]:componnet[{}] finished in {} milliseconds",slot.getRequestId(),this.getClass().getSimpleName(),timeSpent); } protected abstract void process() throws Exception; diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java index 9cd3b52fa..d0e483796 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/DataBus.java @@ -47,9 +47,9 @@ public class DataBus { public static void releaseSlot(int slotIndex){ if(slots[slotIndex] != null){ + LOG.info("[{}]:slot[{}] released",slots[slotIndex].getRequestId(),slotIndex); slots[slotIndex] = null; OCCUPY_COUNT.decrementAndGet(); - LOG.info("slot[{}] released",slotIndex); }else{ LOG.warn("slot[{}] already has been released",slotIndex); } From 5823fa6378ac9acc67ddf01bf99969cd8db63474 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Thu, 11 Jan 2018 15:05:44 +0800 Subject: [PATCH 25/42] submit --- .../java/com/thebeastshop/liteflow/entity/data/AbsSlot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 361593a71..80af5e047 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -117,7 +117,7 @@ public abstract class AbsSlot implements Slot{ str.append("==>"); } } - LOG.info(str.toString()); + LOG.info("[{}]:{}",getRequestId(),str.toString()); } @Override From 142d4d10012b77ad782b9eab92c6f4eee5368147 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Fri, 12 Jan 2018 18:54:29 +0800 Subject: [PATCH 26/42] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0ede7c5e0..fa5355b8d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.9 + 1.2.10 UTF-8 From 4f1e1c47c27c18a5b024573c43d1f594cb9429fc Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 17:42:17 +0800 Subject: [PATCH 27/42] =?UTF-8?q?Chain=E4=B8=AD=E5=A2=9E=E5=8A=A0chainName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../thebeastshop/liteflow/entity/config/Chain.java | 13 ++++++++++++- .../thebeastshop/liteflow/parser/FlowParser.java | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index fa5355b8d..5dd7529f8 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.10 + 1.2.11 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/entity/config/Chain.java b/src/main/java/com/thebeastshop/liteflow/entity/config/Chain.java index 1c4f22a81..bd28dcf5f 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/config/Chain.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/config/Chain.java @@ -13,9 +13,12 @@ import java.util.List; public class Chain { + private String chainName; + private List conditionList; - public Chain(List conditionList) { + public Chain(String chainName, List conditionList) { + this.chainName = chainName; this.conditionList = conditionList; } @@ -26,4 +29,12 @@ public class Chain { public void setConditionList(List conditionList) { this.conditionList = conditionList; } + + public String getChainName() { + return chainName; + } + + public void setChainName(String chainName) { + this.chainName = chainName; + } } diff --git a/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java b/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java index ef3aa4804..6537e376c 100644 --- a/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java +++ b/src/main/java/com/thebeastshop/liteflow/parser/FlowParser.java @@ -127,7 +127,7 @@ public class FlowParser { conditionList.add(new WhenCondition(chainNodeList)); } } - FlowBus.addChain(chainName, new Chain(conditionList)); + FlowBus.addChain(chainName, new Chain(chainName,conditionList)); } } catch (Exception e) { LOG.error("FlowParser parser exception: {}", e); From 617d04315700841b03b5384b9e0b960730f578ef Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 19:25:15 +0800 Subject: [PATCH 28/42] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=AD=E5=8F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5dd7529f8..5ba8929db 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.11 + 1.2.12 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 1eabad407..70787d04a 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -124,6 +124,8 @@ public class FlowExecutor { LOG.info("[{}]:component[{}] lead the chain to end",slot.getRequestId(),component.getClass().getSimpleName()); break; } + }else { + LOG.info("[{}]:component[{}] do not have access",slot.getRequestId(),component.getClass().getSimpleName()); } }catch(Throwable t){ if(component.isContinueOnError()){ From b91227739d1134cf97f2651a4cca1c0b9ea8162f Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 19:42:30 +0800 Subject: [PATCH 29/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwhen=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E4=B8=8D=E8=BF=9BisAccess=E6=96=B9=E6=B3=95=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thebeastshop/liteflow/core/FlowExecutor.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 70787d04a..d01c46784 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -138,7 +138,7 @@ public class FlowExecutor { }else if(condition instanceof WhenCondition){ final CountDownLatch latch = new CountDownLatch(nodeList.size()); for(Node node : nodeList){ - new WhenConditionThread(node,slotIndex,latch).start(); + new WhenConditionThread(node,slotIndex,slot.getRequestId(),latch).start(); } latch.await(15, TimeUnit.SECONDS); } @@ -161,18 +161,26 @@ public class FlowExecutor { private Integer slotIndex; + private String requestId; + private CountDownLatch latch; - public WhenConditionThread(Node node,Integer slotIndex,CountDownLatch latch){ + public WhenConditionThread(Node node,Integer slotIndex,String requestId,CountDownLatch latch){ this.node = node; this.slotIndex = slotIndex; + this.requestId = requestId; this.latch = latch; } @Override public void run() { try{ - node.getInstance().setSlotIndex(slotIndex).execute(); + NodeComponent cmp = node.getInstance().setSlotIndex(slotIndex); + if(cmp.isAccess()) { + cmp.execute(); + }else { + LOG.info("[{}]:component[{}] do not have access",requestId,cmp.getClass().getSimpleName()); + } }catch(Exception e){ LOG.error("component [{}] execute cause error",node.getClazz(),e); }finally{ From ed3be7805e5c6050b2d43f12028b75c3395c6cd8 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 19:43:19 +0800 Subject: [PATCH 30/42] =?UTF-8?q?=E5=8D=87=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5ba8929db..ed57f36d4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.12 + 1.2.13 UTF-8 From 0146658c7c0d4194b27c70cca5cefec1adb168a1 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 20:05:16 +0800 Subject: [PATCH 31/42] =?UTF-8?q?=E4=BF=AE=E6=AD=A3isAccess=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index d01c46784..9a65f0441 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -125,7 +125,7 @@ public class FlowExecutor { break; } }else { - LOG.info("[{}]:component[{}] do not have access",slot.getRequestId(),component.getClass().getSimpleName()); + LOG.info("[{}]:skip component[{}] execution",slot.getRequestId(),component.getClass().getSimpleName()); } }catch(Throwable t){ if(component.isContinueOnError()){ @@ -179,7 +179,7 @@ public class FlowExecutor { if(cmp.isAccess()) { cmp.execute(); }else { - LOG.info("[{}]:component[{}] do not have access",requestId,cmp.getClass().getSimpleName()); + LOG.info("[{}]:skip component[{}] execution",requestId,cmp.getClass().getSimpleName()); } }catch(Exception e){ LOG.error("component [{}] execute cause error",node.getClazz(),e); From 11aeabd354e83078737e5b96463a248de55e371d Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 20:05:50 +0800 Subject: [PATCH 32/42] =?UTF-8?q?=E5=8D=87=E7=89=88=E6=9C=AC=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ed57f36d4..3c05f1230 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.13 + 1.2.14 UTF-8 From 41eb44130dfe9f10f8b964f7a9ce9da88e0c6814 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 20:12:03 +0800 Subject: [PATCH 33/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 4 ++-- .../java/com/thebeastshop/liteflow/core/NodeComponent.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 3c05f1230..57ba5c660 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.14 + 1.2.15 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 9a65f0441..aa5637c1f 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -125,7 +125,7 @@ public class FlowExecutor { break; } }else { - LOG.info("[{}]:skip component[{}] execution",slot.getRequestId(),component.getClass().getSimpleName()); + LOG.info("[{}]:[×]skip component[{}] execution",slot.getRequestId(),component.getClass().getSimpleName()); } }catch(Throwable t){ if(component.isContinueOnError()){ @@ -179,7 +179,7 @@ public class FlowExecutor { if(cmp.isAccess()) { cmp.execute(); }else { - LOG.info("[{}]:skip component[{}] execution",requestId,cmp.getClass().getSimpleName()); + LOG.info("[{}]:[×]skip component[{}] execution",requestId,cmp.getClass().getSimpleName()); } }catch(Exception e){ LOG.error("component [{}] execute cause error",node.getClazz(),e); diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index 87b3dd63f..f114e53ad 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -33,7 +33,7 @@ public abstract class NodeComponent { public void execute() throws Exception{ Slot slot = this.getSlot(); - LOG.info("[{}]:start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName()); + LOG.info("[{}]:[√]start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName()); slot.addStep(new CmpStep(nodeId, CmpStepType.START)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); From a42c3131bd358c3fc4d336259cce7e6837428863 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Wed, 17 Jan 2018 20:21:06 +0800 Subject: [PATCH 34/42] =?UTF-8?q?=E6=94=B9=E5=8F=98access=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E8=AF=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 4 ++-- .../java/com/thebeastshop/liteflow/core/NodeComponent.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 57ba5c660..a72cb0d85 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.15 + 1.2.16 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index aa5637c1f..fa8927e55 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -125,7 +125,7 @@ public class FlowExecutor { break; } }else { - LOG.info("[{}]:[×]skip component[{}] execution",slot.getRequestId(),component.getClass().getSimpleName()); + LOG.info("[{}]:[X]skip component[{}] execution",slot.getRequestId(),component.getClass().getSimpleName()); } }catch(Throwable t){ if(component.isContinueOnError()){ @@ -179,7 +179,7 @@ public class FlowExecutor { if(cmp.isAccess()) { cmp.execute(); }else { - LOG.info("[{}]:[×]skip component[{}] execution",requestId,cmp.getClass().getSimpleName()); + LOG.info("[{}]:[X]skip component[{}] execution",requestId,cmp.getClass().getSimpleName()); } }catch(Exception e){ LOG.error("component [{}] execute cause error",node.getClazz(),e); diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index f114e53ad..612d8d9b5 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -33,7 +33,7 @@ public abstract class NodeComponent { public void execute() throws Exception{ Slot slot = this.getSlot(); - LOG.info("[{}]:[√]start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName()); + LOG.info("[{}]:[O]start component[{}] execution",slot.getRequestId(),this.getClass().getSimpleName()); slot.addStep(new CmpStep(nodeId, CmpStepType.START)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); From d62a05ee87c83ca3bed8cab78418cf019d5b549f Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Thu, 18 Jan 2018 11:42:00 +0800 Subject: [PATCH 35/42] =?UTF-8?q?=E5=9C=A8slot=E9=87=8C=E9=9D=A2=E5=8A=A0?= =?UTF-8?q?=E5=85=A5chainName?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/thebeastshop/liteflow/core/FlowExecutor.java | 1 + .../thebeastshop/liteflow/entity/data/AbsSlot.java | 12 +++++++++++- .../com/thebeastshop/liteflow/entity/data/Slot.java | 4 ++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a72cb0d85..918cb6ba0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.16 + 1.2.17 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index fa8927e55..816fd588f 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -102,6 +102,7 @@ public class FlowExecutor { if(!isInnerChain) { slot.setRequestData(param); + slot.setChainName(chainId); }else { slot.setChainReqData(chainId, param); } diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 80af5e047..13e4393b3 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -28,6 +28,8 @@ public abstract class AbsSlot implements Slot{ private final String RESPONSE = "response"; + private final String CHAINNAME = "chain_name"; + private final String COND_NODE_PREFIX = "cond_"; private final String NODE_INPUT_PREFIX = "input_"; @@ -98,6 +100,14 @@ public abstract class AbsSlot implements Slot{ return (T)dataMap.get(COND_NODE_PREFIX + key); } + public void setChainName(String chainName) { + dataMap.put(CHAINNAME, chainName); + } + + public String getChainName() { + return (String)dataMap.get(CHAINNAME); + } + public void addStep(CmpStep step){ CmpStep lastStep = this.executeSteps.peekLast(); if(lastStep != null && lastStep.equals(step)) { @@ -117,7 +127,7 @@ public abstract class AbsSlot implements Slot{ str.append("==>"); } } - LOG.info("[{}]:{}",getRequestId(),str.toString()); + LOG.info("[{}]:CHAIN_NAME[{}]\n{}",getRequestId(),str.toString()); } @Override diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java index a7163e9a2..7b9913406 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/Slot.java @@ -45,4 +45,8 @@ public interface Slot { public void generateRequestId(); public String getRequestId(); + + public void setChainName(String chainName); + + public String getChainName(); } From 7b5937a0f40bfca50a29f9de6e17a3bc1e64f791 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Thu, 18 Jan 2018 11:53:18 +0800 Subject: [PATCH 36/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8DchainName=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8D=E6=AD=A3=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/thebeastshop/liteflow/entity/data/AbsSlot.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 918cb6ba0..1865eb237 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.17 + 1.2.18 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 13e4393b3..3fa11409f 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -127,7 +127,7 @@ public abstract class AbsSlot implements Slot{ str.append("==>"); } } - LOG.info("[{}]:CHAIN_NAME[{}]\n{}",getRequestId(),str.toString()); + LOG.info("[{}]:CHAIN_NAME[{}]\n{}",getRequestId(),this.getChainName(),str.toString()); } @Override From c14e277b048af340e247cbef18496d23a2f78321 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Thu, 18 Jan 2018 18:28:38 +0800 Subject: [PATCH 37/42] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1865eb237..0960a12d0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.18 + 1.2.19 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 816fd588f..0160c2dff 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -132,6 +132,7 @@ public class FlowExecutor { if(component.isContinueOnError()){ LOG.error("[{}]:component[{}] cause error,but flow is still go on",t,slot.getRequestId(),component.getClass().getSimpleName()); }else{ + LOG.error("[{}]:executor cause error",t,slot.getRequestId()); throw t; } } @@ -146,7 +147,6 @@ public class FlowExecutor { } return (T)slot; }catch(Exception e){ - LOG.error("[{}]:executor cause error",e,slot.getRequestId()); throw new FlowSystemException("executor cause error"); }finally{ if(!isInnerChain) { From 4504baa13fa4362750f3582993f8104cdc936fcc Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Sat, 20 Jan 2018 16:48:22 +0800 Subject: [PATCH 38/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=93=E5=8D=B0?= =?UTF-8?q?=E4=B8=8D=E5=87=BAexception=E7=9A=84stackTrace=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../java/com/thebeastshop/liteflow/core/FlowExecutor.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0960a12d0..0ed5aa39e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.19 + 1.2.20 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java index 0160c2dff..87d73276b 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java +++ b/src/main/java/com/thebeastshop/liteflow/core/FlowExecutor.java @@ -128,11 +128,13 @@ public class FlowExecutor { }else { LOG.info("[{}]:[X]skip component[{}] execution",slot.getRequestId(),component.getClass().getSimpleName()); } - }catch(Throwable t){ + }catch(Exception t){ if(component.isContinueOnError()){ - LOG.error("[{}]:component[{}] cause error,but flow is still go on",t,slot.getRequestId(),component.getClass().getSimpleName()); + String errorMsg = MessageFormat.format("[{0}]:component[{1}] cause error,but flow is still go on", slot.getRequestId(),component.getClass().getSimpleName()); + LOG.error(errorMsg,t); }else{ - LOG.error("[{}]:executor cause error",t,slot.getRequestId()); + String errorMsg = MessageFormat.format("[{0}]:executor cause error",slot.getRequestId()); + LOG.error(errorMsg,t); throw t; } } From ad3967816672adf1250cdfa849b7c56b5eb4f009 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 22 Jan 2018 20:12:21 +0800 Subject: [PATCH 39/42] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../liteflow/monitor/MonitorBus.java | 51 ++++++++++++++----- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 0ed5aa39e..1e5f5bfa0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.20 + 1.2.20-SNAPSHOT UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java index 9c7e06808..8e6d1768b 100644 --- a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java +++ b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java @@ -11,13 +11,19 @@ package com.thebeastshop.liteflow.monitor; import java.math.BigDecimal; import java.math.RoundingMode; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.TimerTask; import java.util.Map.Entry; import java.util.Timer; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.collections4.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +45,7 @@ public class MonitorBus { public void run() { MonitorBus.printStatistics(); } - }, 5*60*1000L, 5*60*1000L); + }, 1*60*1000L, 5*60*1000L); } public static void addStatistics(CompStatistics statistics){ @@ -68,19 +74,40 @@ public class MonitorBus { compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue()); compAverageMemorySpent.put(entry.getKey(), new BigDecimal(totalMemorySpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue()); } - System.out.println("======================================================================================"); - System.out.println("===================================SLOT INFO=========================================="); - System.out.println("SLOT TOTAL SIZE : "+DataBus.SLOT_SIZE); - System.out.println("SLOT OCCUPY COUNT : "+DataBus.OCCUPY_COUNT); - System.out.println("===============================TIME AVERAGE SPENT====================================="); - for(Entry entry : compAverageTimeSpent.entrySet()){ - System.out.println("COMPONENT["+entry.getKey()+"] AVERAGE TIME SPENT : " + entry.getValue()); + + List> compAverageTimeSpentEntryList = new ArrayList<>(compAverageTimeSpent.entrySet()); + List> compAverageMemorySpentEntryList = new ArrayList<>(compAverageMemorySpent.entrySet()); + + Collections.sort(compAverageTimeSpentEntryList,new Comparator>() { + @Override + public int compare(Entry o1, Entry o2) { + return o2.getValue().compareTo(o1.getValue()); + } + }); + + Collections.sort(compAverageMemorySpentEntryList,new Comparator>() { + @Override + public int compare(Entry o1, Entry o2) { + return o2.getValue().compareTo(o1.getValue()); + } + }); + + StringBuilder logStr = new StringBuilder(); + logStr.append("以下为LiteFlow中间件统计信息:\n"); + logStr.append("======================================================================================\n"); + logStr.append("===================================SLOT INFO==========================================\n"); + logStr.append(MessageFormat.format("SLOT TOTAL SIZE : {0}\n", DataBus.SLOT_SIZE)); + logStr.append(MessageFormat.format("SLOT OCCUPY COUNT : {0}\n", DataBus.OCCUPY_COUNT)); + logStr.append("===============================TIME AVERAGE SPENT=====================================\n"); + for(Entry entry : compAverageTimeSpentEntryList){ + logStr.append(MessageFormat.format("COMPONENT[{0}] AVERAGE TIME SPENT : {1}\n", entry.getKey(), entry.getValue())); } - System.out.println("==============================MEMORY AVERAGE SPENT===================================="); - for(Entry entry : compAverageMemorySpent.entrySet()){ - System.out.println("COMPONENT["+entry.getKey()+"] AVERAGE MEMORY SPENT : "+ new BigDecimal(entry.getValue()).divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP) + "K"); + logStr.append("==============================MEMORY AVERAGE SPENT====================================\n"); + for(Entry entry : compAverageMemorySpentEntryList){ + logStr.append(MessageFormat.format("COMPONENT[{0}] AVERAGE MEMORY SPENT : {1}K\n", entry.getKey(), new BigDecimal(entry.getValue()).divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP))); } - System.out.println("======================================================================================"); + logStr.append("======================================================================================\n"); + LOG.info(logStr.toString()); }catch(Exception e){ LOG.error("print statistics cause error",e); } From a71958acdda307031675e669c142f32920346e9d Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 23 Jan 2018 13:56:39 +0800 Subject: [PATCH 40/42] =?UTF-8?q?=E4=BF=AE=E5=A4=8DmonitorBus=E4=B8=AD?= =?UTF-8?q?=E9=99=90=E5=88=B6=E9=98=9F=E5=88=97=E6=B2=A1=E6=9C=89=E9=99=90?= =?UTF-8?q?=E5=88=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/thebeastshop/liteflow/monitor/MonitorBus.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java index 8e6d1768b..8c4ce7de4 100644 --- a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java +++ b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java @@ -45,15 +45,15 @@ public class MonitorBus { public void run() { MonitorBus.printStatistics(); } - }, 1*60*1000L, 5*60*1000L); + }, 5*60*1000L, 5*60*1000L); } public static void addStatistics(CompStatistics statistics){ if(statisticsMap.containsKey(statistics.getComponentClazzName())){ - statisticsMap.get(statistics.getComponentClazzName()).add(statistics); + statisticsMap.get(statistics.getComponentClazzName()).offer(statistics); }else{ LimitQueue queue = new LimitQueue(QUEUE_LIMIT_SIZE); - queue.add(statistics); + queue.offer(statistics); statisticsMap.put(statistics.getComponentClazzName(), queue); } } From da1002957ab512a5200f78d3eed6831f934e23a8 Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Tue, 30 Jan 2018 14:15:36 +0800 Subject: [PATCH 41/42] =?UTF-8?q?=E7=9B=91=E6=8E=A7=E5=99=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E5=8E=BB=E9=99=A4=E5=86=85=E5=AD=98=E7=9A=84?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E3=80=82=20=E6=9C=89=E7=82=B9=E9=B8=A1?= =?UTF-8?q?=E8=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../liteflow/core/NodeComponent.java | 1 - .../liteflow/entity/data/AbsSlot.java | 4 +++ .../liteflow/monitor/MonitorBus.java | 28 ++++--------------- 4 files changed, 11 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 1e5f5bfa0..36916c72f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.2.20-SNAPSHOT + 1.3.0 UTF-8 diff --git a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java index 612d8d9b5..0f77eb276 100644 --- a/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java +++ b/src/main/java/com/thebeastshop/liteflow/core/NodeComponent.java @@ -50,7 +50,6 @@ public abstract class NodeComponent { CompStatistics statistics = new CompStatistics(); statistics.setComponentClazzName(this.getClass().getSimpleName()); statistics.setTimeSpent(timeSpent); - statistics.setMemorySpent(initm-endm); MonitorBus.addStatistics(statistics); diff --git a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java index 3fa11409f..b95c47321 100644 --- a/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java +++ b/src/main/java/com/thebeastshop/liteflow/entity/data/AbsSlot.java @@ -139,4 +139,8 @@ public abstract class AbsSlot implements Slot{ public String getRequestId() { return (String)dataMap.get(REQUEST_ID); } + + public Deque getExecuteSteps() { + return executeSteps; + } } diff --git a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java index 8c4ce7de4..c25973c5a 100644 --- a/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java +++ b/src/main/java/com/thebeastshop/liteflow/monitor/MonitorBus.java @@ -60,34 +60,22 @@ public class MonitorBus { public static void printStatistics(){ try{ - Map compAverageTimeSpent = new HashMap(); - Map compAverageMemorySpent = new HashMap(); + Map compAverageTimeSpent = new HashMap(); long totalTimeSpent = 0; - long totalMemorySpent = 0; for(Entry> entry : statisticsMap.entrySet()){ for(CompStatistics statistics : entry.getValue()){ totalTimeSpent += statistics.getTimeSpent(); - totalMemorySpent += statistics.getMemorySpent(); } - compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue()); - compAverageMemorySpent.put(entry.getKey(), new BigDecimal(totalMemorySpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP).longValue()); + compAverageTimeSpent.put(entry.getKey(), new BigDecimal(totalTimeSpent).divide(new BigDecimal(entry.getValue().size()), 2, RoundingMode.HALF_UP)); } - List> compAverageTimeSpentEntryList = new ArrayList<>(compAverageTimeSpent.entrySet()); - List> compAverageMemorySpentEntryList = new ArrayList<>(compAverageMemorySpent.entrySet()); + List> compAverageTimeSpentEntryList = new ArrayList<>(compAverageTimeSpent.entrySet()); - Collections.sort(compAverageTimeSpentEntryList,new Comparator>() { + Collections.sort(compAverageTimeSpentEntryList,new Comparator>() { @Override - public int compare(Entry o1, Entry o2) { - return o2.getValue().compareTo(o1.getValue()); - } - }); - - Collections.sort(compAverageMemorySpentEntryList,new Comparator>() { - @Override - public int compare(Entry o1, Entry o2) { + public int compare(Entry o1, Entry o2) { return o2.getValue().compareTo(o1.getValue()); } }); @@ -99,13 +87,9 @@ public class MonitorBus { logStr.append(MessageFormat.format("SLOT TOTAL SIZE : {0}\n", DataBus.SLOT_SIZE)); logStr.append(MessageFormat.format("SLOT OCCUPY COUNT : {0}\n", DataBus.OCCUPY_COUNT)); logStr.append("===============================TIME AVERAGE SPENT=====================================\n"); - for(Entry entry : compAverageTimeSpentEntryList){ + for(Entry entry : compAverageTimeSpentEntryList){ logStr.append(MessageFormat.format("COMPONENT[{0}] AVERAGE TIME SPENT : {1}\n", entry.getKey(), entry.getValue())); } - logStr.append("==============================MEMORY AVERAGE SPENT====================================\n"); - for(Entry entry : compAverageMemorySpentEntryList){ - logStr.append(MessageFormat.format("COMPONENT[{0}] AVERAGE MEMORY SPENT : {1}K\n", entry.getKey(), new BigDecimal(entry.getValue()).divide(new BigDecimal(1024), 2, RoundingMode.HALF_UP))); - } logStr.append("======================================================================================\n"); LOG.info(logStr.toString()); }catch(Exception e){ From 65a2bc91e629739d285c5f65a330fc013d574a2e Mon Sep 17 00:00:00 2001 From: "bryan.zhang" Date: Mon, 5 Feb 2018 19:22:08 +0800 Subject: [PATCH 42/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B02.3.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 36916c72f..993677321 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ liteflow jar 4.0.0 - 1.3.0 + 1.3.1 UTF-8 @@ -123,17 +123,4 @@ - - - - nexus-releases - nexus-releases - http://118.178.236.200:8087/nexus/content/repositories/thirdparty - - - nexus-snapshots - nexus-snapshots - http://118.178.236.200:8087/nexus/content/repositories/snapshots - - \ No newline at end of file