enhancement #I691LD 对beforeProcess和afterProcess两个方法进行参数优化
This commit is contained in:
parent
df76a05c4f
commit
db8f38846e
|
@ -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());
|
||||
}
|
||||
|
||||
//是否进入该节点
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue