mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-11 03:13:51 +00:00
ref[net]: refactor generate protocol file
This commit is contained in:
1 parent
02272754f7
commit
d13d90cf9f
3 files changed
+55
-35
No files matched your search
@@ -50,39 +50,6 @@ public class PacketService implements IPacketService {
|
||||
*/
|
||||
public static final int PACKET_HEAD_LENGTH = 4;
|
||||
|
||||
/**
|
||||
* 网络包的约定规则如下:
|
||||
* 1. 客户端的请求约定以Request结尾,服务器的响应约定以Response结尾
|
||||
* 2. 服务器内部请求约定以Ask结尾,服务器内部的响应约定以Answer结尾
|
||||
* 3. 服务器主动通知客户端以Notice结尾
|
||||
* 4. 公共的协议放在common模块
|
||||
* 5. 内部协议范围不允许使用
|
||||
*/
|
||||
public static final String NET_REQUEST_SUFFIX = "Request";
|
||||
public static final String NET_RESPONSE_SUFFIX = "Response";
|
||||
|
||||
public static final String NET_ASK_SUFFIX = "Ask";
|
||||
public static final String NET_ANSWER_SUFFIX = "Answer";
|
||||
|
||||
public static final String NET_NOTICE_SUFFIX = "Notice";
|
||||
|
||||
|
||||
public static final String NET_COMMON_MODULE = "common";
|
||||
|
||||
public static final Predicate<IProtocolRegistration> netGenerateProtocolFilter = it -> {
|
||||
var clazz = it.protocolConstructor().getDeclaringClass();
|
||||
var className = clazz.getSimpleName();
|
||||
if (className.endsWith(NET_ASK_SUFFIX) || className.endsWith(NET_ANSWER_SUFFIX)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var module = ProtocolManager.moduleByModuleId(it.module());
|
||||
return clazz == SignalAttachment.class
|
||||
|| className.endsWith(NET_REQUEST_SUFFIX)
|
||||
|| className.endsWith(NET_RESPONSE_SUFFIX)
|
||||
|| className.endsWith(NET_NOTICE_SUFFIX)
|
||||
|| module.getName().matches(NET_COMMON_MODULE);
|
||||
};
|
||||
|
||||
public PacketService() {
|
||||
|
||||
@@ -110,7 +77,7 @@ public class PacketService implements IPacketService {
|
||||
generateOperation.getGenerateLanguages().addAll(codeLanguageSet);
|
||||
}
|
||||
// 设置生成协议的过滤器
|
||||
GenerateProtocolFile.generateProtocolFilter = netGenerateProtocolFilter;
|
||||
GenerateProtocolFile.generateProtocolFilter = GenerateProtocolFile.DefaultNetGenerateProtocolFilter;
|
||||
|
||||
// 解析protocol.xml文件,并将协议生成ProtocolRegistration
|
||||
var resource = applicationContext.getResource(ResourceUtils.CLASSPATH_URL_PREFIX + protocolLocation);
|
||||
|
||||
@@ -41,6 +41,7 @@ import com.zfoo.protocol.ProtocolManager;
|
||||
import com.zfoo.protocol.collection.ArrayUtils;
|
||||
import com.zfoo.protocol.exception.ExceptionUtils;
|
||||
import com.zfoo.protocol.exception.RunException;
|
||||
import com.zfoo.protocol.generate.GenerateProtocolFile;
|
||||
import com.zfoo.protocol.util.*;
|
||||
import io.netty.util.collection.ShortObjectHashMap;
|
||||
import org.slf4j.Logger;
|
||||
@@ -436,7 +437,7 @@ public class Router implements IRouter {
|
||||
// These rules are not necessary, but can reduce us from making low-level mistakes
|
||||
// If the request class name ends with Request which is for outer net client, then the attachment can not be a SignalAttachment
|
||||
// If the request class name ends with Ask which is for intranet client, then attachment can not be a GatewayAttachment
|
||||
if (attachmentClazz != null && packetName.endsWith(PacketService.NET_ASK_SUFFIX)) {
|
||||
if (attachmentClazz != null && packetName.endsWith(GenerateProtocolFile.NET_ASK_SUFFIX)) {
|
||||
AssertionUtils.isTrue(!attachmentClazz.equals(GatewayAttachment.class), "[class:{}] [method:{}] [packet:{}] can not match with [attachment:{}]!", bean.getClass().getName(), methodName, packetName, GatewayAttachment.class.getCanonicalName());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user