mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-10-19 20:15:46 +00:00
perf[net]: 校验一个协议只能对应一个被@PacketReceiver标注的方法
This commit is contained in:
1 parent
4a188eb565
commit
6acd609cbf
1 file changed
+8
-10
@@ -48,12 +48,6 @@ public abstract class PacketBus {
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(PacketBus.class);
|
private static final Logger logger = LoggerFactory.getLogger(PacketBus.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端和服务端都有接受packet的方法,packetReceiverList对应的就是包的接收方法,将receiver注册到IProtocolRegistration
|
|
||||||
*/
|
|
||||||
public static final IProtocolRegistration[] packetReceiverList = ProtocolManager.protocols;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 正常消息的接收
|
* 正常消息的接收
|
||||||
* <p>
|
* <p>
|
||||||
@@ -61,7 +55,8 @@ public abstract class PacketBus {
|
|||||||
* 接收者同时只能处理一个session的一个包,同一个发送者发送过来的包排队处理
|
* 接收者同时只能处理一个session的一个包,同一个发送者发送过来的包排队处理
|
||||||
*/
|
*/
|
||||||
public static void submit(Session session, IPacket packet, IAttachment attachment) {
|
public static void submit(Session session, IPacket packet, IAttachment attachment) {
|
||||||
var packetReceiver = (IPacketReceiver) packetReceiverList[packet.protocolId()].receiver();
|
// 客户端和服务端都有接受packet的方法,packetReceiverList对应的就是包的接收方法,将receiver注册到IProtocolRegistration
|
||||||
|
var packetReceiver = (IPacketReceiver) ProtocolManager.getProtocol(packet.protocolId()).receiver();
|
||||||
if (packetReceiver == null) {
|
if (packetReceiver == null) {
|
||||||
throw new RuntimeException(StringUtils.format("no any packetReceiverDefinition found for this [packet:{}]", packet.getClass().getName()));
|
throw new RuntimeException(StringUtils.format("no any packetReceiverDefinition found for this [packet:{}]", packet.getClass().getName()));
|
||||||
}
|
}
|
||||||
@@ -127,12 +122,15 @@ public abstract class PacketBus {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
var protocolId = ProtocolAnalysis.getProtocolIdByClass(packetClazz);
|
var protocolId = ProtocolAnalysis.getProtocolIdByClass(packetClazz);
|
||||||
var receiverDefinition = new PacketReceiverDefinition(bean, method, packetClazz, attachmentClazz);
|
|
||||||
var enhanceReceiverDefinition = EnhanceUtils.createPacketReceiver(receiverDefinition);
|
|
||||||
|
|
||||||
// 将receiver注册到IProtocolRegistration
|
// 将receiver注册到IProtocolRegistration
|
||||||
var protocolRegistration = packetReceiverList[protocolId];
|
var protocolRegistration = ProtocolManager.getProtocol(protocolId);
|
||||||
AssertionUtils.notNull(protocolRegistration, "协议类[class:{}][protocolId:{}]没有注册", packetClazz.getSimpleName(), protocolId);
|
AssertionUtils.notNull(protocolRegistration, "协议类[class:{}][protocolId:{}]没有注册", packetClazz.getSimpleName(), protocolId);
|
||||||
|
AssertionUtils.isNull(protocolRegistration.receiver(), "协议类[class:{}]被重复接收[at{}],一个协议只能对应一个被@PacketReceiver标注的方法"
|
||||||
|
, packetClazz.getSimpleName(), packetClazz.getSimpleName());
|
||||||
|
|
||||||
|
var receiverDefinition = new PacketReceiverDefinition(bean, method, packetClazz, attachmentClazz);
|
||||||
|
var enhanceReceiverDefinition = EnhanceUtils.createPacketReceiver(receiverDefinition);
|
||||||
|
|
||||||
var receiverField = ReflectionUtils.getFieldByNameInPOJOClass(protocolRegistration.getClass(), "receiver");
|
var receiverField = ReflectionUtils.getFieldByNameInPOJOClass(protocolRegistration.getClass(), "receiver");
|
||||||
ReflectionUtils.makeAccessible(receiverField);
|
ReflectionUtils.makeAccessible(receiverField);
|
||||||
|
|||||||
Reference in new issue
Block a user