11111
parent
1443bf6a06
commit
c1a3bb406b
|
@ -15,7 +15,7 @@ public class EngineConfig {
|
||||||
/**
|
/**
|
||||||
* 包名称
|
* 包名称
|
||||||
*/
|
*/
|
||||||
private String pack ="com.ecology.etl.engine.";
|
private String pack ="com.muyu.rule.server.";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本地目录名称
|
* 本地目录名称
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.rule.server;
|
||||||
|
|
||||||
|
|
||||||
import com.muyu.rule.server.complie.SourceCodeComplier;
|
import com.muyu.rule.server.complie.SourceCodeComplier;
|
||||||
|
import com.muyu.rule.server.execution.EngineExecution;
|
||||||
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
import com.muyu.rule.server.load.JavaBinaryClassLoader;
|
||||||
import com.muyu.rule.server.pool.container.EngineContainer;
|
import com.muyu.rule.server.pool.container.EngineContainer;
|
||||||
|
|
||||||
|
@ -24,16 +25,17 @@ public class EngineTest {
|
||||||
//扫描原码进行编译
|
//扫描原码进行编译
|
||||||
SourceCodeComplier.javaCompilerPath(engineConfig.getLocation());
|
SourceCodeComplier.javaCompilerPath(engineConfig.getLocation());
|
||||||
|
|
||||||
Map<String ,Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getPack(),engineConfig.getLocation());
|
Map<String ,Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getPack(),engineConfig.getLocation());
|
||||||
|
|
||||||
stringClassMap.forEach((key,value)->{
|
stringClassMap.forEach((key,value)->{
|
||||||
EngineContainer.loadEngineInstance(key,value);
|
EngineContainer.loadEngineInstance(key,value);
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, Object> params = new HashMap<>();
|
Map<String, Object> params = new HashMap<>();
|
||||||
params.put("idCard","");
|
params.put("idcard","142021 200212215977");
|
||||||
|
Object engineObject = EngineExecution.engineExe("Engine_2020_11_3_2347", params);
|
||||||
//EngineExecution.engineExe(,params);
|
//
|
||||||
|
// System.out.println(engineObject);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,9 +95,9 @@ public class EtlRuleController {
|
||||||
* @param id 主键
|
* @param id 主键
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
@DeleteMapping
|
@DeleteMapping("/{id}")
|
||||||
@Operation(summary = "规则引擎的删除", description = "通过Id删除规则信息")
|
@Operation(summary = "规则引擎的删除", description = "通过Id删除规则信息")
|
||||||
public Result<Boolean> deleteById(int id){
|
public Result<Boolean> deleteById(@PathVariable("id") int id){
|
||||||
etlRuleService.deleteById(id);
|
etlRuleService.deleteById(id);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,14 +39,16 @@ public class JavaBinaryClassLoader extends ClassLoader{
|
||||||
|
|
||||||
|
|
||||||
private static Class<?> loadClassByNameAndLocation(String name,String pack,File location){
|
private static Class<?> loadClassByNameAndLocation(String name,String pack,File location){
|
||||||
Class<?> aClass = null;
|
|
||||||
try {
|
try {
|
||||||
//将class文件的数据读入到byte数组中 转成二进制文件
|
//将class文件的数据读入到byte数组中 转成二进制文件
|
||||||
byte[] datas = loader.loadClassData(name,location);
|
byte[] datas = loader.loadClassData(name,location);
|
||||||
pack= loader.convert(pack);
|
pack= loader.convert(pack);
|
||||||
|
System.out.println(pack+"======"+name);
|
||||||
//通过byte数组加载Class对象
|
//通过byte数组加载Class对象
|
||||||
aClass = loader.defineClass(pack + name, datas, 0, datas.length);
|
String cc = pack+name;
|
||||||
|
System.out.println(cc);
|
||||||
|
Class<?> aClass = loader.defineClass(cc, datas, 0, datas.length);
|
||||||
log.info("成功加载规则引擎-> {} ",aClass.getName());
|
log.info("成功加载规则引擎-> {} ",aClass.getName());
|
||||||
return aClass;
|
return aClass;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -62,12 +64,14 @@ return aClass;
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map<String ,Class<?>> loadClassesByLocation(String pack,String location){
|
public static Map<String ,Class<?>> loadClassesByLocation(String pack,String location){
|
||||||
|
int count =0;
|
||||||
File[] childFiles = JavaCodeScan.javaBinaryByPath(location);
|
File[] childFiles = JavaCodeScan.javaBinaryByPath(location);
|
||||||
HashMap<String, Class<?>> map = new HashMap<>();
|
HashMap<String, Class<?>> map = new HashMap<>();
|
||||||
for (File f : childFiles) {
|
for (File f : childFiles) {
|
||||||
String name = f.getName().substring(0, f.getName().indexOf(".class"));
|
String name = f.getName().substring(0, f.getName().indexOf(".class"));
|
||||||
|
|
||||||
Class<?> c = loadClassByNameAndLocation(name,pack,new File(location));
|
Class<?> c = loadClassByNameAndLocation(name,pack,new File(location));
|
||||||
|
System.out.println(++count);
|
||||||
map.put(name,c);
|
map.put(name,c);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
|
@ -79,7 +83,7 @@ return map;
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String convert(String pack) {
|
private String convert(String pack) {
|
||||||
return pack.replace('.', '/') + "/";
|
return pack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] loadClassData(String name, File location)throws IOException {
|
public byte[] loadClassData(String name, File location)throws IOException {
|
||||||
|
|
|
@ -96,6 +96,7 @@ return null;
|
||||||
public static List<String> getMethodEngineParamMap(String engineKey) {
|
public static List<String> getMethodEngineParamMap(String engineKey) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,4 +115,10 @@ return null;
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getSumEngine() {
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue