master
parent
996d5e33d6
commit
af1685f245
|
@ -1,5 +1,6 @@
|
|||
package com.muyu;
|
||||
|
||||
import com.muyu.domain.EngineVersion;
|
||||
import com.muyu.handler.DataEngineHandler;
|
||||
|
||||
public interface BasicEngine<V> {
|
||||
|
@ -14,4 +15,5 @@ public interface BasicEngine<V> {
|
|||
|
||||
public void execution();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.muyu.req.EngineVersionListResp;
|
|||
import com.muyu.service.EngIneService;
|
||||
import com.muyu.service.EngineVersionService;
|
||||
import com.muyu.test.ExternalClassLoader;
|
||||
import jakarta.validation.Path;
|
||||
import com.muyu.test.TestService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -23,8 +23,10 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.muyu.test.RuleTest.engineWorkSourcePath;
|
||||
|
||||
|
@ -45,38 +47,47 @@ public class EngIneServiceImpl extends ServiceImpl<EngineMapper, EngineMaintenan
|
|||
@Autowired
|
||||
private EngineVersionService engineConfigService;
|
||||
|
||||
public static final String packagePath = "com.muyu.test";
|
||||
public static final ConcurrentHashMap<Object, Object> engineMap = new ConcurrentHashMap<Object, Object>();
|
||||
private static final String objectPath = "com.muyu.test";
|
||||
|
||||
@Override
|
||||
public Object measurementList(EngineVersion engineVersion) {
|
||||
// EngineVersion dataValue = engineVersion;
|
||||
// String versionClass = engineVersion.getVersionClass();
|
||||
// CompileService.test(engineVersion.getVersionCode(), engineVersion.getVersionClass());
|
||||
// try {
|
||||
// //外部类文件路径
|
||||
// String externalClassFilePath = engineWorkSourcePath + "/" + objectPath + "/" + versionClass + ".class";
|
||||
// Path classFilePath = Paths.get(externalClassFilePath);
|
||||
// //获取外部类所在的目录
|
||||
// String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||
// URL[] urls = null;
|
||||
// urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||
// //创建自定义类加载
|
||||
// ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||
//
|
||||
// //加载类
|
||||
// Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, packagePath + "." + versionClass);
|
||||
// //创建类的实例
|
||||
// Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
//
|
||||
// engineMap.put(versionClass, (BasicEngine<DataValue>) instance);
|
||||
// } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||
// IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//
|
||||
// BasicEngine<DataValue> engine = engineMap.get(versionClass);
|
||||
// engine.set(dataValue);
|
||||
// engine.execution();
|
||||
// return Result.success();
|
||||
return null;
|
||||
EngineVersion dataValue = engineVersion;
|
||||
String versionClass = engineVersion.getVersionClass();
|
||||
TestService.test(engineVersion);
|
||||
try {
|
||||
//外部类文件路径
|
||||
String externalClassFilePath = engineWorkSourcePath + "/" + objectPath + "/" + versionClass + ".class";
|
||||
Path classFilePath = Paths.get(externalClassFilePath);
|
||||
//获取外部类所在的目录
|
||||
String externalClassDir = externalClassFilePath.substring(0, externalClassFilePath.lastIndexOf('/'));
|
||||
URL[] urls = null;
|
||||
urls = new URL[]{new File(externalClassDir).toURI().toURL()};
|
||||
//创建自定义类加载
|
||||
ExternalClassLoader externalClassLoader = new ExternalClassLoader(urls);
|
||||
|
||||
//加载类
|
||||
Class<?> clazz = externalClassLoader.loadClassFromPath(classFilePath, packagePath + "." + versionClass);
|
||||
//创建类的实例
|
||||
Object instance = clazz.getDeclaredConstructor().newInstance();
|
||||
|
||||
engineMap.put(versionClass, instance);
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException |
|
||||
IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
BasicEngine<DataValue> engine = (BasicEngine<DataValue>) engineMap.get(versionClass);
|
||||
try {
|
||||
engine.set(DataValue.class.newInstance());
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
engine.execution();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue