mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 04:02:09 +08:00
bug #ICZ1M1 解决在2.15.0中,获取Annotation缺失了缓存导致的性能微小损失问题
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
package com.yomahub.liteflow.annotation;
|
||||||
|
|
||||||
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.AnnotatedElement;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class AnnoUtil {
|
||||||
|
|
||||||
|
private static Map<String, Annotation> annoCacheMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType) {
|
||||||
|
String cacheKey = StrUtil.format("{}-{}", annotatedElement, annotationType.getSimpleName());
|
||||||
|
|
||||||
|
if (annoCacheMap.containsKey(cacheKey)){
|
||||||
|
return (A)annoCacheMap.get(cacheKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
A annotation = AnnotationUtil.getAnnotationAlias(annotatedElement, annotationType);
|
||||||
|
|
||||||
|
if (annotation == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
annoCacheMap.put(cacheKey, annotation);
|
||||||
|
|
||||||
|
return annotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.yomahub.liteflow.core;
|
|||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.yomahub.liteflow.annotation.AnnoUtil;
|
||||||
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
import com.yomahub.liteflow.annotation.LiteflowRetry;
|
||||||
import com.yomahub.liteflow.common.ChainConstant;
|
import com.yomahub.liteflow.common.ChainConstant;
|
||||||
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
import com.yomahub.liteflow.enums.NodeTypeEnum;
|
||||||
@@ -53,7 +54,7 @@ public class ComponentInitializer {
|
|||||||
|
|
||||||
// 先从组件上取@RetryCount标注,如果没有,则看全局配置,全局配置如果不配置的话,默认是0
|
// 先从组件上取@RetryCount标注,如果没有,则看全局配置,全局配置如果不配置的话,默认是0
|
||||||
// 默认retryForExceptions为Exception.class
|
// 默认retryForExceptions为Exception.class
|
||||||
LiteflowRetry liteFlowRetryAnnotation = AnnotationUtil.getAnnotationAlias(nodeComponent.getClass(), LiteflowRetry.class);
|
LiteflowRetry liteFlowRetryAnnotation = AnnoUtil.getAnnotation(nodeComponent.getClass(), LiteflowRetry.class);
|
||||||
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
LiteflowConfig liteflowConfig = LiteflowConfigGetter.get();
|
||||||
if (liteFlowRetryAnnotation != null) {
|
if (liteFlowRetryAnnotation != null) {
|
||||||
nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry());
|
nodeComponent.setRetryCount(liteFlowRetryAnnotation.retry());
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import cn.hutool.core.map.MapUtil;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.yomahub.liteflow.annotation.AnnoUtil;
|
||||||
import com.yomahub.liteflow.context.ContextBean;
|
import com.yomahub.liteflow.context.ContextBean;
|
||||||
import com.yomahub.liteflow.log.LFLog;
|
import com.yomahub.liteflow.log.LFLog;
|
||||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||||
@@ -83,7 +84,7 @@ public class DataBus {
|
|||||||
|
|
||||||
public static int offerSlotByBean(List<Object> contextList) {
|
public static int offerSlotByBean(List<Object> contextList) {
|
||||||
List<Tuple> contextBeanList = contextList.stream().filter(Objects::nonNull).map(object -> {
|
List<Tuple> contextBeanList = contextList.stream().filter(Objects::nonNull).map(object -> {
|
||||||
ContextBean contextBean = AnnotationUtil.getAnnotationAlias(object.getClass(), ContextBean.class);
|
ContextBean contextBean = AnnoUtil.getAnnotation(object.getClass(), ContextBean.class);
|
||||||
String contextKey;
|
String contextKey;
|
||||||
if (contextBean != null && StrUtil.isNotBlank(contextBean.value())){
|
if (contextBean != null && StrUtil.isNotBlank(contextBean.value())){
|
||||||
contextKey = contextBean.value();
|
contextKey = contextBean.value();
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ public class SolonDeclComponentParser implements DeclComponentParser {
|
|||||||
method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) != null
|
method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) != null
|
||||||
).map(method -> {
|
).map(method -> {
|
||||||
LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class);
|
LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class);
|
||||||
LiteflowRetry liteflowRetry = AnnotationUtil.getAnnotationAlias(method, LiteflowRetry.class);
|
LiteflowRetry liteflowRetry = AnnoUtil.getAnnotation(method, LiteflowRetry.class);
|
||||||
|
|
||||||
String currNodeId = null;
|
String currNodeId = null;
|
||||||
String currNodeName = null;
|
String currNodeName = null;
|
||||||
if (nodeId == null){
|
if (nodeId == null){
|
||||||
if (StrUtil.isBlank(liteflowMethod.nodeId())){
|
if (StrUtil.isBlank(liteflowMethod.nodeId())){
|
||||||
LiteflowComponent liteflowComponent = AnnotationUtil.getAnnotationAlias(clazz, LiteflowComponent.class);
|
LiteflowComponent liteflowComponent = AnnoUtil.getAnnotation(clazz, LiteflowComponent.class);
|
||||||
Component component = AnnotationUtil.getAnnotation(clazz, Component.class);
|
Component component = AnnotationUtil.getAnnotation(clazz, Component.class);
|
||||||
|
|
||||||
if(liteflowComponent != null){
|
if(liteflowComponent != null){
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.yomahub.liteflow.process.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.annotation.AnnotationUtil;
|
import cn.hutool.core.annotation.AnnotationUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.yomahub.liteflow.annotation.AnnoUtil;
|
||||||
import com.yomahub.liteflow.process.LiteflowScannerProcessStep;
|
import com.yomahub.liteflow.process.LiteflowScannerProcessStep;
|
||||||
import com.yomahub.liteflow.process.context.LiteflowScannerProcessStepContext;
|
import com.yomahub.liteflow.process.context.LiteflowScannerProcessStepContext;
|
||||||
import com.yomahub.liteflow.process.enums.LiteflowScannerProcessStepEnum;
|
import com.yomahub.liteflow.process.enums.LiteflowScannerProcessStepEnum;
|
||||||
@@ -24,7 +25,7 @@ public class ScriptBeanProcess implements LiteflowScannerProcessStep {
|
|||||||
public boolean filter(LiteflowScannerProcessStepContext ctx) {
|
public boolean filter(LiteflowScannerProcessStepContext ctx) {
|
||||||
Class clazz = ctx.getClazz();
|
Class clazz = ctx.getClazz();
|
||||||
|
|
||||||
ScriptBean outPut = AnnotationUtil.getAnnotationAlias(clazz, ScriptBean.class);
|
ScriptBean outPut = AnnoUtil.getAnnotation(clazz, ScriptBean.class);
|
||||||
ctx.setOutPut(outPut);
|
ctx.setOutPut(outPut);
|
||||||
|
|
||||||
return ObjectUtil.isNotNull(outPut);
|
return ObjectUtil.isNotNull(outPut);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class SpringDeclComponentParser implements DeclComponentParser {
|
|||||||
method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) != null
|
method -> AnnotationUtil.getAnnotation(method, LiteflowMethod.class) != null
|
||||||
).map(method -> {
|
).map(method -> {
|
||||||
LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class);
|
LiteflowMethod liteflowMethod = AnnotationUtil.getAnnotation(method, LiteflowMethod.class);
|
||||||
LiteflowRetry liteflowRetry = AnnotationUtil.getAnnotationAlias(method, LiteflowRetry.class);
|
LiteflowRetry liteflowRetry = AnnoUtil.getAnnotation(method, LiteflowRetry.class);
|
||||||
|
|
||||||
String currNodeId = null;
|
String currNodeId = null;
|
||||||
String currNodeName = null;
|
String currNodeName = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user