11111
parent
afe53281d5
commit
f42ff2dd35
|
@ -67,7 +67,6 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bucket名称
|
* bucket名称
|
||||||
*
|
*
|
||||||
|
@ -77,6 +76,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传
|
* 上传
|
||||||
|
*
|
||||||
* @param versionClazz java源代码
|
* @param versionClazz java源代码
|
||||||
* @param className 类的名
|
* @param className 类的名
|
||||||
*/
|
*/
|
||||||
|
@ -98,6 +98,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||||
public static final String engineWorkSourcePath = "home/source/";
|
public static final String engineWorkSourcePath = "home/source/";
|
||||||
public static final String engineWorkClassPath = "home/class/";
|
public static final String engineWorkClassPath = "home/class/";
|
||||||
|
@ -106,8 +107,7 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
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
|
@Override
|
||||||
public void HotLoadClass(String className, String versionClazz) {
|
public void HotLoadClass(String className, String versionClazz) {
|
||||||
try {
|
try {
|
||||||
|
@ -120,12 +120,12 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
//创建服务器项目容器的文件目录路径
|
//创建服务器项目容器的文件目录路径
|
||||||
File serverFile = new File(engineWorkSourcePath, ossFilePath);
|
File serverFile = new File(engineWorkSourcePath, ossFilePath);
|
||||||
//如果目录不存在,则创建目录
|
//如果目录不存在,则创建目录
|
||||||
if (!serverFile.getParentFile().exists()){
|
if (!serverFile.getParentFile().exists()) {
|
||||||
serverFile.getParentFile().mkdirs();
|
serverFile.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
File classFile = new File(engineWorkClassPath, ossFilePath2);
|
File classFile = new File(engineWorkClassPath, ossFilePath2);
|
||||||
//如果目录不存在,则创建目录
|
//如果目录不存在,则创建目录
|
||||||
if (!classFile.getParentFile().exists()){
|
if (!classFile.getParentFile().exists()) {
|
||||||
classFile.getParentFile().mkdirs();
|
classFile.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
//下载文件到指定服务器目录下
|
//下载文件到指定服务器目录下
|
||||||
|
@ -138,20 +138,20 @@ public class RuleEngineVersionServiceImpl extends ServiceImpl<RuleEngineVersionM
|
||||||
OutputStream second = null; // 程序的输出 null 用 system.out
|
OutputStream second = null; // 程序的输出 null 用 system.out
|
||||||
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
OutputStream third = null; // 程序的错误输出 .,null 用 system.err
|
||||||
// 程序编译参数 注意 我们编译目录是我们的项目目录
|
// 程序编译参数 注意 我们编译目录是我们的项目目录
|
||||||
String[] strings = {"-classpath", "home/lib", "-verbose", "-d", "home/lib", "home/source/"+className+".java"};
|
String[] strings = {"-classpath", "home/lib", "-verbose", "-d", "home/lib", "home/source/" + className + ".java"};
|
||||||
log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
log.info("规则引擎的编译参数{}[]", Arrays.toString(strings));
|
||||||
// 0 表示成功, 其他表示出现了错误
|
// 0 表示成功, 其他表示出现了错误
|
||||||
System.out.println(Arrays.toString(strings));
|
System.out.println(Arrays.toString(strings));
|
||||||
int i = javaCompiler.run(first, second, third, strings);
|
int i = javaCompiler.run(first, second, third, strings);
|
||||||
|
|
||||||
if (i == 0 ) {
|
if (i == 0) {
|
||||||
System.out.println("成功");
|
System.out.println("成功");
|
||||||
}else {
|
} else {
|
||||||
System.out.println("错误");
|
System.out.println("错误");
|
||||||
}
|
}
|
||||||
// 假设这是你的外部类文件路径
|
// 假设这是你的外部类文件路径
|
||||||
String externalClassFilePath =
|
String externalClassFilePath =
|
||||||
"home/lib/"+"com/muyu/rule/common/basic/engine/value/" +className+Suffix_CLASS;
|
"home/lib/" + "com/muyu/rule/common/basic/engine/value/" + 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()};
|
||||||
|
@ -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();
|
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||||
|
@ -192,29 +192,8 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
||||||
engine.execution();
|
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
|
@Override
|
||||||
public void testValue(String versionClazz, DataValue dataValue) {
|
public void testValue(String versionClazz, DataValue dataValue) {
|
||||||
|
@ -228,9 +207,9 @@ log.info("规则引擎的编译参数{}[]",Arrays.toString(strings));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void testEngine(String className,Object object) {
|
public void testEngine(String className, Object object) {
|
||||||
log.info("数据:"+object);
|
log.info("数据:" + object);
|
||||||
DataValue basicEngine = (DataValue)object;
|
DataValue basicEngine = (DataValue) object;
|
||||||
|
|
||||||
BasicEngine<DataValue> valueBasicEngine = engineMap.get(basicEngine);
|
BasicEngine<DataValue> valueBasicEngine = engineMap.get(basicEngine);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue