enhancement: #I1Z96F liteflow系统级别增加切面的支持

This commit is contained in:
bryan31
2020-10-22 21:33:26 +08:00
parent f47f6a61b0
commit 89400aa74d
4 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
/**
* <p>Title: liteflow</p>
* <p>Description: 轻量级的组件式流程框架</p>
* @author Bryan.Zhang
* @email weenyc31@163.com
* @Date 2020/10/22
*/
package com.yomahub.liteflow.aop;
import com.yomahub.liteflow.entity.data.Slot;
public interface ICmpAroundAspect {
void beforeProcess(Slot slot);
void afterProcess(Slot slot);
}

View File

@@ -8,6 +8,7 @@
package com.yomahub.liteflow.core;
import com.yomahub.liteflow.entity.flow.Executable;
import com.yomahub.liteflow.spring.ComponentScaner;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
@@ -40,8 +41,18 @@ public abstract class NodeComponent {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//process前置处理
if(ComponentScaner.cmpAroundAspect != null){
ComponentScaner.cmpAroundAspect.beforeProcess(slot);
}
process();
//process后置处理
if(ComponentScaner.cmpAroundAspect != null){
ComponentScaner.cmpAroundAspect.afterProcess(slot);
}
stopWatch.stop();
long timeSpent = stopWatch.getTime();

View File

@@ -9,6 +9,8 @@ package com.yomahub.liteflow.spring;
import java.util.HashMap;
import java.util.Map;
import com.yomahub.liteflow.aop.ICmpAroundAspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
@@ -24,6 +26,8 @@ public class ComponentScaner implements BeanPostProcessor, PriorityOrdered {
public static Map<String, NodeComponent> nodeComponentMap = new HashMap<String, NodeComponent>();
public static ICmpAroundAspect cmpAroundAspect;
static {
LOGOPrinter.print();
}
@@ -37,12 +41,20 @@ public class ComponentScaner implements BeanPostProcessor, PriorityOrdered {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
Class clazz = bean.getClass();
//组件的扫描发现
if(NodeComponent.class.isAssignableFrom(clazz)){
LOG.info("component[{}] has been found",beanName);
NodeComponent nodeComponent = (NodeComponent)bean;
nodeComponent.setNodeId(beanName);
nodeComponentMap.put(beanName, nodeComponent);
}
//组件Aop的实现类加载
if(ICmpAroundAspect.class.isAssignableFrom(clazz)){
LOG.info("component aspect implement[{}] has been found",beanName);
cmpAroundAspect = (ICmpAroundAspect)bean;
}
return bean;
}

View File

@@ -0,0 +1,18 @@
package com.yomahub.flowtest.aspect;
import com.yomahub.liteflow.aop.ICmpAroundAspect;
import com.yomahub.liteflow.entity.data.Slot;
import org.springframework.stereotype.Component;
@Component
public class ComponentAspect implements ICmpAroundAspect {
@Override
public void beforeProcess(Slot slot) {
System.out.println("before process");
}
@Override
public void afterProcess(Slot slot) {
System.out.println("after process");
}
}