mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-04 06:20:19 +00:00
perf[protocol]: 优化协议检查提示
This commit is contained in:
@@ -149,6 +149,14 @@ public class ProtocolManager {
|
||||
public static synchronized void initProtocol(Set<Class<?>> protocolClassSet, GenerateOperation generateOperation) {
|
||||
AssertionUtils.notNull(tempSubProtocolIdMap, "[{}]已经初始完成,只能parseProtocol一次,请不要重复初始化", ProtocolManager.class.getSimpleName());
|
||||
try {
|
||||
for (var protocolClass : protocolClassSet) {
|
||||
var id = getProtocolIdByClass(protocolClass);
|
||||
var previous = tempProtocolClassMap.put(id, protocolClass);
|
||||
if (previous != null) {
|
||||
throw new RunException("[{}][{}]协议号[protocolId:{}]重复", protocolClass.getCanonicalName(), previous.getCanonicalName(), id);
|
||||
}
|
||||
}
|
||||
|
||||
for (var protocolClass : protocolClassSet) {
|
||||
try {
|
||||
var registration = parseProtocolRegistration(protocolClass, ProtocolModule.DEFAULT_PROTOCOL_MODULE);
|
||||
@@ -199,7 +207,10 @@ public class ProtocolManager {
|
||||
// 协议号是否和id是否相等
|
||||
AssertionUtils.isTrue(packet.protocolId() == id, "[class:{}]协议序列号[{}]和协议文件里的协议序列号不相等", clazz.getCanonicalName(), PROTOCOL_ID);
|
||||
|
||||
tempProtocolClassMap.put(id, clazz);
|
||||
var previous = tempProtocolClassMap.put(id, clazz);
|
||||
if (previous != null) {
|
||||
throw new RunException("[{}][{}]协议号[protocolId:{}]重复", clazz.getCanonicalName(), previous.getCanonicalName(), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,10 +402,6 @@ public class ProtocolManager {
|
||||
private static ProtocolRegistration parseProtocolRegistration(Class<?> clazz, ProtocolModule module) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException {
|
||||
var protocolId = checkProtocol(clazz);
|
||||
|
||||
if (protocols[protocolId] != null) {
|
||||
throw new RunException("[{}][{}]协议号[protocolId:{}]重复", protocols[protocolId].protocolConstructor().getDeclaringClass().getCanonicalName(), clazz.getCanonicalName(), protocolId);
|
||||
}
|
||||
|
||||
var fields = new ArrayList<Field>();
|
||||
for (var field : clazz.getDeclaredFields()) {
|
||||
var modifiers = field.getModifiers();
|
||||
|
||||
Reference in New Issue
Block a user