11111
parent
afe53281d5
commit
f42ff2dd35
|
@ -67,7 +67,6 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
*
|
||||
|
@ -77,6 +76,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
|||
|
||||
/**
|
||||
* 上传
|
||||
*
|
||||
* @param versionClazz java源代码
|
||||
* @param className 类的名
|
||||
*/
|
||||
|
@ -98,61 +98,61 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
|||
|
||||
return string;
|
||||
}
|
||||
|
||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
public static final String engineWorkSourcePath = "home/source/";
|
||||
public static final String engineWorkClassPath = "home/class/";
|
||||
//
|
||||
//
|
||||
public static final String className_prefix = "com.muyu.rule.common.basic.engine.value.";
|
||||
//
|
||||
public static final String className_prefix = "com.muyu.rule.common.basic.engine.value.";
|
||||
|
||||
|
||||
|
||||
//todo
|
||||
//todo
|
||||
@Override
|
||||
public void HotLoadClass(String className, String versionClazz) {
|
||||
try {
|
||||
String ossFilePath = className + Suffix_JAVA;
|
||||
String ossFilePath2 = className + Suffix_CLASS;
|
||||
EngineConfig engineConfig = new EngineConfig();
|
||||
String ossFilePath = className + Suffix_JAVA;
|
||||
String ossFilePath2 = className + Suffix_CLASS;
|
||||
EngineConfig engineConfig = new EngineConfig();
|
||||
|
||||
// String filePath ="home/"+ossFilePath;
|
||||
String filePath = engineConfig.getSourcePath() + ossFilePath;
|
||||
// String filePath ="home/"+ossFilePath;
|
||||
String filePath = engineConfig.getSourcePath() + ossFilePath;
|
||||
//创建服务器项目容器的文件目录路径
|
||||
File serverFile = new File(engineWorkSourcePath, ossFilePath);
|
||||
//如果目录不存在,则创建目录
|
||||
if (!serverFile.getParentFile().exists()){
|
||||
if (!serverFile.getParentFile().exists()) {
|
||||
serverFile.getParentFile().mkdirs();
|
||||
}
|
||||
File classFile = new File(engineWorkClassPath, ossFilePath2);
|
||||
//如果目录不存在,则创建目录
|
||||
if (!classFile.getParentFile().exists()){
|
||||
if (!classFile.getParentFile().exists()) {
|
||||
classFile.getParentFile().mkdirs();
|
||||
}
|
||||
//下载文件到指定服务器目录下
|
||||
OssUtil.downloadFileForBucket(bucketName, ossFilePath, filePath);
|
||||
OssUtil.downloadFileForBucket(bucketName, ossFilePath, filePath);
|
||||
//编译
|
||||
|
||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||
//
|
||||
InputStream first = null; // 程序的输入 null 用 system.in
|
||||
OutputStream second = null; // 程序的输出 null 用 system.out
|
||||
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
||||
// 程序编译参数 注意 我们编译目录是我们的项目目录
|
||||
String[] strings = {"-classpath", "home/lib", "-verbose", "-d", "home/lib", "home/source/"+className+".java"};
|
||||
log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
||||
// 0 表示成功, 其他表示出现了错误
|
||||
System.out.println(Arrays.toString(strings));
|
||||
int i = javaCompiler.run(first, second, third, strings);
|
||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||
//
|
||||
InputStream first = null; // 程序的输入 null 用 system.in
|
||||
OutputStream second = null; // 程序的输出 null 用 system.out
|
||||
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
||||
// 程序编译参数 注意 我们编译目录是我们的项目目录
|
||||
String[] strings = {"-classpath", "home/lib", "-verbose", "-d", "home/lib", "home/source/" + className + ".java"};
|
||||
log.info("规则引擎的编译参数{}[]", Arrays.toString(strings));
|
||||
// 0 表示成功, 其他表示出现了错误
|
||||
System.out.println(Arrays.toString(strings));
|
||||
int i = javaCompiler.run(first, second, third, strings);
|
||||
|
||||
if (i == 0 ) {
|
||||
System.out.println("成功");
|
||||
}else {
|
||||
System.out.println("错误");
|
||||
}
|
||||
// 假设这是你的外部类文件路径
|
||||
String externalClassFilePath =
|
||||
"home/lib/"+"com/muyu/rule/common/basic/engine/value/" +className+Suffix_CLASS;
|
||||
Path classFilePath = Paths.get(externalClassFilePath);
|
||||
if (i == 0) {
|
||||
System.out.println("成功");
|
||||
} else {
|
||||
System.out.println("错误");
|
||||
}
|
||||
// 假设这是你的外部类文件路径
|
||||
String externalClassFilePath =
|
||||
"home/lib/" + "com/muyu/rule/common/basic/engine/value/" + className + Suffix_CLASS;
|
||||
Path classFilePath = Paths.get(externalClassFilePath);
|
||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||
URL[] urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||
|
||||
|
@ -161,7 +161,7 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
|||
|
||||
//加载类
|
||||
//注意类名必须是完全限定名(包括包名)
|
||||
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath,className_prefix+className);
|
||||
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, className_prefix + className);
|
||||
|
||||
//创建类的实例
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
@ -192,29 +192,8 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
|||
engine.execution();
|
||||
|
||||
|
||||
//对class文件进行自定义类加载规则引擎
|
||||
// Map<String, Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getServerPack(), engineConfig.getClassPath());
|
||||
}
|
||||
|
||||
// static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
//
|
||||
// static {
|
||||
// try {
|
||||
// Class<?> aClass = Class.forName("com.muyu.rule.common.basic.engine.value.ENGINE_VALUE_VFD1000_V1");
|
||||
// Class<?> aClass2 = Class.forName("com.muyu.rule.common.basic.engine.value.ENGINE_VALUE_VFD1000_V2");
|
||||
// try {
|
||||
// engineMap.put("ENGINE_VALUE_VFD1000_V1", (BasicEngine<DataValue>) aClass.newInstance());
|
||||
// engineMap.put("ENGINE_VALUE_VFD1000_V2", (BasicEngine<DataValue>) aClass2.newInstance());
|
||||
// } catch (InstantiationException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } catch (IllegalAccessException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void testValue(String versionClazz, DataValue dataValue) {
|
||||
|
@ -228,9 +207,9 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
|||
}
|
||||
|
||||
@Override
|
||||
public void testEngine(String className,Object object) {
|
||||
log.info("数据:"+object);
|
||||
DataValue basicEngine = (DataValue)object;
|
||||
public void testEngine(String className, Object object) {
|
||||
log.info("数据:" + object);
|
||||
DataValue basicEngine = (DataValue) object;
|
||||
|
||||
BasicEngine<DataValue> valueBasicEngine = engineMap.get(basicEngine);
|
||||
|
||||
|
|
Loading…
Reference in New Issue