From db8f38846e96b8616ad7bedcfbe94a3ea30b8a0c Mon Sep 17 00:00:00 2001 From: "everywhere.z" Date: Thu, 5 Jan 2023 19:51:27 +0800 Subject: [PATCH] =?UTF-8?q?enhancement=20#I691LD=20=E5=AF=B9beforeProcess?= =?UTF-8?q?=E5=92=8CafterProcess=E4=B8=A4=E4=B8=AA=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E5=8F=82=E6=95=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yomahub/liteflow/core/NodeComponent.java | 12 ++++----- .../liteflow/core/proxy/ComponentProxy.java | 27 +++++++------------ .../liteflow/solon/NodeComponentOfMethod.java | 4 +-- .../test/customMethodName/cmp/CmpConfig.java | 4 +-- .../test/customMethodName/cmp/ACmp.java | 4 +-- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java index a9f075f0e..de2e6a1ca 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/NodeComponent.java @@ -92,7 +92,7 @@ public abstract class NodeComponent{ try{ //前置处理 - self.beforeProcess(this.getNodeId(), slot); + self.beforeProcess(); //主要的处理逻辑 self.process(); @@ -118,7 +118,7 @@ public abstract class NodeComponent{ throw e; } finally { //后置处理 - self.afterProcess(this.getNodeId(), slot); + self.afterProcess(); stopWatch.stop(); final long timeSpent = stopWatch.getTotalTimeMillis(); @@ -135,10 +135,10 @@ public abstract class NodeComponent{ } } - public void beforeProcess(String nodeId, Slot slot){ + public void beforeProcess(){ //全局切面只在spring体系下生效,这里用了spi机制取到相应环境下的实现类 //非spring环境下,全局切面为空实现 - CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(nodeId, slot); + CmpAroundAspectHolder.loadCmpAroundAspect().beforeProcess(nodeId, this.getSlot()); } public abstract void process() throws Exception; @@ -151,8 +151,8 @@ public abstract class NodeComponent{ //如果需要在抛错后回调某一段逻辑,请覆盖这个方法 } - public void afterProcess(String nodeId, Slot slot){ - CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(nodeId, slot); + public void afterProcess(){ + CmpAroundAspectHolder.loadCmpAroundAspect().afterProcess(nodeId, this.getSlot()); } //是否进入该节点 diff --git a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java index 4af0b8dd8..eb54fb175 100644 --- a/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java +++ b/liteflow-core/src/main/java/com/yomahub/liteflow/core/proxy/ComponentProxy.java @@ -194,26 +194,17 @@ public class ComponentProxy { ).findFirst().orElse(null); //如果被代理的对象里有此标注标的方法,则调用此被代理的对象里的方法,如果没有,则调用父类里的方法 - //beforeProcess和afterProcess这2个方法除外 - if (!ListUtil.toList("beforeProcess","afterProcess").contains(liteFlowMethodBean.getMethodName())) { - //进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 - boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 - && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); - if (!checkFlag) { - String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); - LOG.error(errMsg); - throw new ComponentMethodDefineErrorException(errMsg); - } - - try{ - return liteFlowMethodBean.getMethod().invoke(bean, proxy); - }catch (Exception e){ - InvocationTargetException targetEx = (InvocationTargetException)e; - throw targetEx.getTargetException(); - } + //进行检查,检查被代理的bean里是否有且仅有NodeComponent这个类型的参数 + boolean checkFlag = liteFlowMethodBean.getMethod().getParameterTypes().length == 1 + && Arrays.asList(liteFlowMethodBean.getMethod().getParameterTypes()).contains(NodeComponent.class); + if (!checkFlag) { + String errMsg = StrUtil.format("Method[{}.{}] must have NodeComponent parameter(and only one parameter)", bean.getClass().getName(), liteFlowMethodBean.getMethod().getName()); + LOG.error(errMsg); + throw new ComponentMethodDefineErrorException(errMsg); } + try{ - return liteFlowMethodBean.getMethod().invoke(bean, args); + return liteFlowMethodBean.getMethod().invoke(bean, proxy); }catch (Exception e){ InvocationTargetException targetEx = (InvocationTargetException)e; throw targetEx.getTargetException(); diff --git a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java index fbc58edb3..c2665b9dc 100644 --- a/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java +++ b/liteflow-solon-plugin/src/main/java/com/yomahub/liteflow/solon/NodeComponentOfMethod.java @@ -53,7 +53,7 @@ public class NodeComponentOfMethod extends NodeComponent { @Override - public void beforeProcess(String nodeId, Slot slot) { + public void beforeProcess() { if(methodEnum != LiteFlowMethodEnum.BEFORE_PROCESS){ return; } @@ -68,7 +68,7 @@ public class NodeComponentOfMethod extends NodeComponent { } @Override - public void afterProcess(String nodeId, Slot slot) { + public void afterProcess() { if (methodEnum != LiteFlowMethodEnum.AFTER_PROCESS) { return; } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java index fd6293ca6..54ca00a24 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-multi-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/CmpConfig.java @@ -20,12 +20,12 @@ public class CmpConfig { } @LiteflowMethod(value = LiteFlowMethodEnum.BEFORE_PROCESS,nodeId = "a") - public void beforeAcmp(String nodeId, Slot slot){ + public void beforeAcmp(NodeComponent bindCmp){ System.out.println("before A"); } @LiteflowMethod(value = LiteFlowMethodEnum.AFTER_PROCESS,nodeId = "a") - public void afterAcmp(String nodeId, Slot slot){ + public void afterAcmp(NodeComponent bindCmp){ System.out.println("after A"); } diff --git a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java index 6944cecd8..acfbcbf06 100644 --- a/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java +++ b/liteflow-testcase-el/liteflow-testcase-el-declare-springboot/src/test/java/com/yomahub/liteflow/test/customMethodName/cmp/ACmp.java @@ -27,12 +27,12 @@ public class ACmp{ } @LiteflowMethod(LiteFlowMethodEnum.BEFORE_PROCESS) - public void beforeAcmp(String nodeId, Slot slot){ + public void beforeAcmp(NodeComponent bindCmp){ System.out.println("before A"); } @LiteflowMethod(LiteFlowMethodEnum.AFTER_PROCESS) - public void afterAcmp(String nodeId, Slot slot){ + public void afterAcmp(NodeComponent bindCmp){ System.out.println("after A"); }