mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
enhancement: #I1Z96F liteflow系统级别增加切面的支持
This commit is contained in:
@@ -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);
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user