11111
parent
bbd20c85ed
commit
63052ba57f
|
@ -1,58 +0,0 @@
|
|||
package com.muyu.rule.common.domain;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
class Person {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Person person = (Person) o;
|
||||
return age == person.age &&
|
||||
Objects.equals(name, person.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"name='" + name + '\'' +
|
||||
", age=" + age +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Person[] people = new Person[]{
|
||||
new Person("Alice", 30),
|
||||
new Person("Alice", 30),
|
||||
new Person("Bob", 25),
|
||||
new Person("Alice", 30),
|
||||
new Person("Charlie", 35)
|
||||
};
|
||||
|
||||
// 使用 HashSet 去重
|
||||
Set<Person> uniquePeople = new HashSet<>(Arrays.asList(people));
|
||||
|
||||
// 将 Set 转换回数组
|
||||
Person[] uniqueArray = uniquePeople.toArray(new Person[0]);
|
||||
|
||||
// 输出结果
|
||||
System.out.println(Arrays.toString(uniqueArray));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.muyu.rule.server;
|
||||
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
|
@ -38,12 +40,13 @@ public class EngineConfig {
|
|||
/**
|
||||
* 服务器的源文件位置
|
||||
*/
|
||||
private static String serverPath ="home/source/";
|
||||
private String sourcePath ="home/source/";
|
||||
|
||||
/**
|
||||
* 服务器的编译文件位置
|
||||
*/
|
||||
private static String ClassPath ="home/class/";
|
||||
@Setter
|
||||
private String classPath ="home/class/";
|
||||
|
||||
/**
|
||||
* 服务器目录路径
|
||||
|
@ -60,12 +63,21 @@ public class EngineConfig {
|
|||
|
||||
private String serverPack="com.muyu.rule.server.basic.engine.value.";
|
||||
|
||||
public String getServerPath() {
|
||||
return serverPath;
|
||||
|
||||
public String getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public void setServerPath(String serverPath) {
|
||||
this.serverPath = serverPath;
|
||||
public void setPack(String pack) {
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getLocalSource() {
|
||||
|
@ -84,6 +96,22 @@ public class EngineConfig {
|
|||
this.localTarget = localTarget;
|
||||
}
|
||||
|
||||
public String getSourcePath() {
|
||||
return sourcePath;
|
||||
}
|
||||
|
||||
public void setSourcePath(String sourcePath) {
|
||||
this.sourcePath = sourcePath;
|
||||
}
|
||||
|
||||
public String getClassPath() {
|
||||
return classPath;
|
||||
}
|
||||
|
||||
public void setClassPath(String classPath) {
|
||||
this.classPath = classPath;
|
||||
}
|
||||
|
||||
public String getServerPack() {
|
||||
return serverPack;
|
||||
}
|
||||
|
@ -91,23 +119,4 @@ public class EngineConfig {
|
|||
public void setServerPack(String serverPack) {
|
||||
this.serverPack = serverPack;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getPack() {
|
||||
return pack;
|
||||
}
|
||||
|
||||
public void setPack(String pack) {
|
||||
|
||||
this.pack = pack;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ public class EngineTest {
|
|||
Object engineObject = EngineExecution.engineExe("Engine_2024_8_23_2347", params);
|
||||
|
||||
System.out.println("====>"+engineObject);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,23 +13,19 @@ import com.muyu.rule.common.domain.DataValue;
|
|||
public class DataEngineValueHandler {
|
||||
|
||||
|
||||
public static void set(DataValue dataDescribe){
|
||||
public static void set(DataValue dataValue){
|
||||
|
||||
DataEngineHandler.set(dataValue);
|
||||
|
||||
DataEngineHandler.set(dataDescribe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static DataValue get(){
|
||||
return DataEngineHandler.get();
|
||||
}
|
||||
|
||||
|
||||
public static void remove(){
|
||||
DataEngineHandler.remove();
|
||||
}
|
||||
|
||||
|
||||
public static Object getValue(){
|
||||
return get().getValue();
|
||||
}
|
||||
|
@ -38,7 +34,4 @@ public class DataEngineValueHandler {
|
|||
return Convert.toInt(getValue(),null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -52,12 +52,14 @@ public class DataSourceDisposeController {
|
|||
|
||||
/**
|
||||
* 对字段进行测试
|
||||
* @param dataValue
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
|
||||
@PostMapping("/valueTest")
|
||||
public Result valueTest(DataValue dataValue){
|
||||
public Result valueTest(Object object){
|
||||
|
||||
sourceDisposeService.valueTest(object);
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
|
|
@ -146,25 +146,6 @@ public Result testValue(@PathVariable("versionClazz") String versionClazz,@Reque
|
|||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/test")
|
||||
public Result test(){
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.rule.server.load;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ExternalClassLoader extends URLClassLoader {
|
||||
|
||||
public ExternalClassLoader(URL[] urls) {
|
||||
super(urls, Thread.currentThread().getContextClassLoader());
|
||||
}
|
||||
|
||||
public Class<?> defineClassFromBytes(byte[] classBytes, String className) throws IOException {
|
||||
return super.defineClass(className, classBytes, 0, classBytes.length);
|
||||
}
|
||||
|
||||
public Class<?> loadClassFromPath(Path classFilePath, String className) throws IOException {
|
||||
byte[] classData = Files.readAllBytes(classFilePath);
|
||||
return defineClassFromBytes(classData, className);
|
||||
}
|
||||
}
|
|
@ -28,4 +28,6 @@ public interface SourceDisposeService {
|
|||
|
||||
|
||||
Boolean notEmpty(Object dataSource);
|
||||
|
||||
String valueTest(Object object);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.muyu.rule.server.service;
|
||||
|
||||
/**
|
||||
* @Author:张承志
|
||||
* @Package:com.muyu.rule.server.service
|
||||
* @Project:cloud-etl-rule
|
||||
* @name:TestServer
|
||||
* @Date:2024/9/4 18:56
|
||||
*/
|
||||
public class TestServer {
|
||||
}
|
|
@ -20,11 +20,16 @@ import com.muyu.rule.server.service.RuleEngineVersionService;
|
|||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.tools.JavaCompiler;
|
||||
import javax.tools.ToolProvider;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -107,14 +112,34 @@ public class RuleEngineServiceImpl extends ServiceImpl<RuleEngineVersionMapper,
|
|||
EngineConfig engineConfig = new EngineConfig();
|
||||
|
||||
// String filePath ="home/"+ossFilePath;
|
||||
String filePath = engineConfig.getServerPath() + ossFilePath;
|
||||
String filePath = engineConfig.getSourcePath() + ossFilePath;
|
||||
//下载容器
|
||||
OssUtil.downloadFileForBucket(bucketName, ossFilePath, filePath);
|
||||
//编译
|
||||
SourceCodeComplier.javaCompilerPath(engineConfig.getServerPath());
|
||||
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",engineConfig.getSourcePath(),"-verbose","-d", engineConfig.getSourcePath(), engineConfig.getSourcePath() +"\\"+className+Suffix_JAVA};
|
||||
|
||||
// 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 =
|
||||
engineConfig.getSourcePath() + "\\com\\muyu\\data\\engine\\service\\"+className+Suffix_JAVA;
|
||||
Path classFilePath = Paths.get(externalClassFilePath);
|
||||
|
||||
//对class文件进行自定义类加载规则引擎
|
||||
Map<String, Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getServerPack(), engineConfig.getServerPath());
|
||||
Map<String, Class<?>> stringClassMap = JavaBinaryClassLoader.loadClassesByLocation(engineConfig.getServerPack(), engineConfig.getClassPath());
|
||||
}
|
||||
|
||||
static Map<String, BasicEngine<DataValue>> engineMap = new ConcurrentHashMap<>();
|
||||
|
|
|
@ -36,4 +36,13 @@ public class SourceDisposeServiceImpl implements SourceDisposeService {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueTest(Object object) {
|
||||
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue