enhancement #I691LD 对beforeProcess和afterProcess两个方法进行参数优化

This commit is contained in:
everywhere.z 2023-01-05 19:51:27 +08:00
parent df76a05c4f
commit db8f38846e
5 changed files with 21 additions and 30 deletions

View File

@ -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());
}
//是否进入该节点

View File

@ -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();

View File

@ -53,7 +53,7 @@ public class NodeComponentOfMethod extends NodeComponent {
@Override
public <T> 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 <T> void afterProcess(String nodeId, Slot slot) {
public void afterProcess() {
if (methodEnum != LiteFlowMethodEnum.AFTER_PROCESS) {
return;
}

View File

@ -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");
}

View File

@ -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");
}