muyu-rule/muyu-rule-server/src/main/java/com/muyu/rule/build/EngineContainer.java

118 lines
4.6 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//package com.muyu.rule.build;
//
//import com.muyu.rule.engine.annotation.EngineParam;
//import com.muyu.rule.exception.RuleEngineException;
//import com.muyu.rule.scan.EngineConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.web.bind.annotation.RequestParam;
//
//import java.lang.annotation.Annotation;
//import java.lang.reflect.Method;
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.List;
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @ClassName EngineContainer
// * @Description 描述
// * @Author Chen
// * @Date 2024/8/29 19:39
// */
//@Slf4j
//public class EngineContainer {
// private static Map<String, Object> instanceMap = new ConcurrentHashMap<>(16);
// private static Map<String, Object> classMap = new ConcurrentHashMap<>(16);
// private static Map<String, Method> methodMap = new ConcurrentHashMap<>(16);
//
// /**
// * 缓存规则引擎
// * @param engineKey
// * @param clazz
// */
// public static void loadEngineInstace(String engineKey, Class<?> clazz) {
// Method method = findMethodByClass(EngineConfig.executionMethodName, clazz);
// if (method == null) {
// log.info("初始化规则引擎->{} 失败缺少 {} 方法", engineKey, EngineConfig.executionMethodName);
// return;
// }
// try {
// instanceMap.put(engineKey, clazz.newInstance());
// } catch (InstantiationException e) {
// throw new RuntimeException(e);
// } catch (IllegalAccessException e) {
// throw new RuntimeException(e);
// }
// classMap.put(engineKey, clazz);
// methodMap.put(engineKey, method);
// Class<?>[] parameterTypes = method.getParameterTypes();
// Annotation[][] parameterAnnotations = method.getParameterAnnotations();
// //获取参数
// List<String> engineParams = new ArrayList<>();
// int parameterTypeLength = parameterTypes.length;
// for (int i = 0; i < parameterTypeLength; i++) {
// Annotation[] paramAnn = parameterAnnotations[i];
// if (paramAnn.length == 0) {
// throw new RuleEngineException("请给所有参数填写注解!");
// }
// if (paramAnn.length > 1) {
// throw new RuleEngineException("参数仅支持一个注解!!!");
// }
// EngineParam engineParam = null;
// if (paramAnn[0] instanceof EngineParam) {
// engineParam = (EngineParam) paramAnn[0];
// }
// if (engineParam == null) {
// throw new RuleEngineException("请使用EngineParam注解");
// } else if (engineParam.name() == null) {
// throw new RuleEngineException("EngineParam--name 不能为空!!");
// }
// engineParams.add(engineParam.name());
// log.info("初始化规则引擎完成 ->规则引擎名称:{} 执行方法:{} 参数名称:{}", engineKey, method.getName(), engineParams.toString());
// }
// }
//
// private static Method findMethodByClass(String methodName, Class<?> clazz) {
// Method[] methods = clazz.getDeclaredMethods();
// return Arrays.stream(methods)
// .filter(method -> method.getName().equals(methodName))
// .findFirst()
// .orElse(null);
// }
//
// public static List<String> getMethodEngineParamMap(String engineKey) {
// Method method = methodMap.get(engineKey);
// if (method == null) {
// return new ArrayList<>();
// }
// Class<?>[] parameterTypes = method.getParameterTypes();
// Annotation[][] parameterAnnotations = method.getParameterAnnotations();
// List<String> params = new ArrayList<>();
// for (int i = 0; i < parameterTypes.length; i++) {
// Annotation[] paramAnn = parameterAnnotations[i];
// if (paramAnn.length == 0) {
// continue;
// }
// EngineParam engineParam = (EngineParam) paramAnn[0];
// if (engineParam != null && !engineParam.name().isEmpty()) {
// params.add(engineParam.name());
// }
// }
// return params;
// }
//
// public static Object getInstanceMap(String engineKey) {
// return instanceMap.get(engineKey);
// }
//
// public static Method getMethodMap(String engineKey) {
// return methodMap.get(engineKey);
// }
//
// public static int getSumEngine() {
// return classMap.size();
// }
//
//}