11111
parent
3b71011bcb
commit
f01450fd2c
|
@ -84,7 +84,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
/**
|
/**
|
||||||
* 将java源码存入OSS
|
* 将java源码存入OSS
|
||||||
*/
|
*/
|
||||||
OssUtil.deliteOssClient(className+Suffix_CLASS);
|
OssUtil.deliteOssClient(className + Suffix_CLASS);
|
||||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(versionClazz.getBytes());
|
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(versionClazz.getBytes());
|
||||||
OssUtil.uploadFileInputStreamForBucket(bucketName, className + Suffix_CLASS, byteArrayInputStream);
|
OssUtil.uploadFileInputStreamForBucket(bucketName, className + Suffix_CLASS, byteArrayInputStream);
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
/**
|
/**
|
||||||
* 引擎加载需要引入类和包文件的位置
|
* 引擎加载需要引入类和包文件的位置
|
||||||
*/
|
*/
|
||||||
public static final String importClassAndPackPath="home/lib/";
|
public static final String importClassAndPackPath = "home/lib/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 规则引擎的包的路径
|
* 规则引擎的包的路径
|
||||||
|
@ -122,6 +122,7 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务器存放引擎的class文件的位置
|
* 服务器存放引擎的class文件的位置
|
||||||
|
*
|
||||||
* @param className 类名
|
* @param className 类名
|
||||||
* @param versionClazz 源代码
|
* @param versionClazz 源代码
|
||||||
*/
|
*/
|
||||||
|
@ -132,7 +133,7 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
//todo
|
//todo
|
||||||
@Override
|
@Override
|
||||||
public void complierClass(String className, String versionClazz) {
|
public void complierClass(String className, String versionClazz) {
|
||||||
log.info("======>"+versionClazz);
|
log.info("======>" + versionClazz);
|
||||||
String ossFilePath = className + Suffix_JAVA;
|
String ossFilePath = className + Suffix_JAVA;
|
||||||
//创建服务器项目容器的java源码文件目录路径
|
//创建服务器项目容器的java源码文件目录路径
|
||||||
File serverFile = new File(engineWorkSourcePath, ossFilePath);
|
File serverFile = new File(engineWorkSourcePath, ossFilePath);
|
||||||
|
@ -141,11 +142,11 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
serverFile.getParentFile().mkdirs();
|
serverFile.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(serverFile))) {
|
try (BufferedWriter writer = new BufferedWriter(new FileWriter(serverFile))) {
|
||||||
writer.write(versionClazz);
|
writer.write(versionClazz);
|
||||||
System.out.println("文件已成功创建并写入Java源码。");
|
System.out.println("文件已成功创建并写入Java源码。");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("发生错误:" + e.getMessage());
|
System.err.println("发生错误:" + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||||
//
|
//
|
||||||
|
@ -171,46 +172,43 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载规则引擎
|
* 加载规则引擎
|
||||||
|
*
|
||||||
* @param className 规则引擎类名
|
* @param className 规则引擎类名
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void loadValueEngineClass(String className) {
|
public void loadValueEngineClass(String className) {
|
||||||
|
|
||||||
//查询类是否已加载,避免重复加载规则引擎
|
//查询类是否已加载,避免重复加载规则引擎
|
||||||
if(!engineMap.containsKey(className)){
|
if (!engineMap.containsKey(className)) {
|
||||||
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
||||||
|
|
||||||
Object instance = loadMethod(className);
|
Object instance = loadMethod(className);
|
||||||
//将加载出来引擎实例存入map集合中
|
//将加载出来引擎实例存入map集合中
|
||||||
engineMap.put(className, (BasicEngine<DataValue>) instance);
|
engineMap.put(className, (BasicEngine<DataValue>) instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Object loadMethod(String className) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Object loadMethod(String className){
|
|
||||||
try {
|
try {
|
||||||
// 假设这是你的外部类文件路径
|
// 假设这是你的外部类文件路径
|
||||||
String externalClassFilePath =
|
String externalClassFilePath =
|
||||||
importClassAndPackPath + serverClassPath + className + Suffix_CLASS;
|
importClassAndPackPath + serverClassPath + className + Suffix_CLASS;
|
||||||
Path classFilePath = Paths.get(externalClassFilePath);
|
Path classFilePath = Paths.get(externalClassFilePath);
|
||||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||||
|
|
||||||
//创建自定义类加载器
|
//创建自定义类加载器
|
||||||
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||||
|
|
||||||
//加载类
|
//加载类
|
||||||
//注意类名必须是完全限定名(包括包名)
|
//注意类名必须是完全限定名(包括包名)
|
||||||
Class<?> clazz = null;
|
Class<?> clazz = null;
|
||||||
|
|
||||||
clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
||||||
//创建类的实例
|
//创建类的实例
|
||||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
return instance;
|
return instance;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
|
@ -227,12 +225,13 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实现测试数据
|
* 实现测试数据
|
||||||
|
*
|
||||||
* @param className 类名
|
* @param className 类名
|
||||||
* @param dataValue ktvl数据
|
* @param dataValue ktvl数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void testEngine(String className, DataValue dataValue) {
|
public void testEngine(String className, DataValue dataValue) {
|
||||||
log.info("测试的数据[]{}:" +dataValue);
|
log.info("测试的数据[]{}:" + dataValue);
|
||||||
|
|
||||||
BasicEngine<DataValue> valueBasicEngine = engineMap.get(className);
|
BasicEngine<DataValue> valueBasicEngine = engineMap.get(className);
|
||||||
|
|
||||||
|
@ -245,11 +244,6 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
public String deposit(Integer type) {
|
public String deposit(Integer type) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +261,7 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
public void loadDateSetEngineClass(String className) {
|
public void loadDateSetEngineClass(String className) {
|
||||||
|
|
||||||
//查询类是否已加载,避免重复加载规则引擎
|
//查询类是否已加载,避免重复加载规则引擎
|
||||||
if(!engineDataSetMap.containsKey(className)){
|
if (!engineDataSetMap.containsKey(className)) {
|
||||||
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
log.info("引擎map集合下没有该实例的规则,进行自定义类加载");
|
||||||
|
|
||||||
Object instance = loadMethod(className);
|
Object instance = loadMethod(className);
|
||||||
|
@ -276,7 +270,6 @@ public static final String importClassAndPackPath="home/lib/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue