mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-19 23:26:50 +00:00
perf[protocol]: scan protocol class
This commit is contained in:
+12
-12
@@ -72,6 +72,18 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- json,bytecode generation to replace use of Reflection for field access and method calls(Jackson涡轮增压,字节码增强解析json) -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-afterburner</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
@@ -103,18 +115,6 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- json,bytecode generation to replace use of Reflection for field access and method calls(Jackson涡轮增压,字节码增强解析json) -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.module</groupId>
|
||||
<artifactId>jackson-module-afterburner</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
|
||||
@@ -177,7 +177,7 @@ public class ProtocolAnalysis {
|
||||
for (var protocolDefinition : moduleDefinition.getProtocols()) {
|
||||
protocolDefinitionMap.put(protocolDefinition.getLocation(), protocolDefinition.isEnhance());
|
||||
protocolNameMap.put(protocolDefinition.getLocation(), protocolDefinition.getId());
|
||||
var packetClazzList = Set.of(ClassUtils.forName(protocolDefinition.getLocation()));
|
||||
var packetClazzList = scanPackageList(protocolDefinition.getLocation());
|
||||
clazzSet.addAll(packetClazzList);
|
||||
for (Class<?> clazz : packetClazzList) {
|
||||
var previous = classModuleDefinitionMap.put(clazz, module.getId());
|
||||
@@ -215,16 +215,34 @@ public class ProtocolAnalysis {
|
||||
enhance(generateOperation, enhanceList);
|
||||
}
|
||||
|
||||
public static Set<Class<?>> scanPackageList(String packageName) {
|
||||
//获取该路径下所有类
|
||||
var clazzSet = new HashSet<String>();
|
||||
public static Set<Class<?>> scanPackageList(String location) {
|
||||
// Use the class path first to obtain the class name, and search the directory if it cannot be obtained
|
||||
// 优先使用类路径获取类名,获取不到才去搜索目录
|
||||
try {
|
||||
var clazzList = ClassUtils.getAllClasses(packageName);
|
||||
clazzSet.addAll(clazzList);
|
||||
var clazz = ClassUtils.forName(location);
|
||||
return Set.of(clazz);
|
||||
} catch (Exception e) {
|
||||
throw new RunException("[{}]包扫描类异常", packageName, e);
|
||||
}
|
||||
return clazzSet.stream().map(it -> ClassUtils.forName(it)).collect(Collectors.toSet());
|
||||
|
||||
// 获取该路径下所有类
|
||||
var clazzNameSet = new HashSet<String>();
|
||||
try {
|
||||
var clazzList = ClassUtils.getAllClasses(location);
|
||||
clazzNameSet.addAll(clazzList);
|
||||
} catch (Exception e) {
|
||||
throw new RunException("[{}] scanning exception", location, e);
|
||||
}
|
||||
var classes = clazzNameSet.stream()
|
||||
.map(it -> ClassUtils.forName(it))
|
||||
.filter(it -> it.isAnnotationPresent(Protocol.class))
|
||||
.filter(it -> !it.isInterface())
|
||||
.filter(it -> !it.isEnum())
|
||||
.distinct()
|
||||
.toList();
|
||||
if (CollectionUtils.isEmpty(classes)) {
|
||||
throw new RunException("can not scan any protocol class in [{}]", location);
|
||||
}
|
||||
return new HashSet<>(classes);
|
||||
}
|
||||
|
||||
private static void enhance(GenerateOperation generateOperation, List<IProtocolRegistration> enhanceList) {
|
||||
|
||||
Reference in New Issue
Block a user