mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-18 19:26:42 +00:00
perf[net]: 简化代码
This commit is contained in:
@@ -64,10 +64,10 @@ public class GatewayRouteHandler extends ServerRouteHandler {
|
||||
|
||||
var decodedPacketInfo = (DecodedPacketInfo) msg;
|
||||
var packet = decodedPacketInfo.getPacket();
|
||||
if (packet.protocolId() == Heartbeat.heartbeatProtocolId()) {
|
||||
if (packet.protocolId() == Heartbeat.PROTOCOL_ID) {
|
||||
return;
|
||||
}
|
||||
if (packet.protocolId() == Ping.pingProtocolId()) {
|
||||
if (packet.protocolId() == Ping.PROTOCOL_ID) {
|
||||
NetContext.getRouter().send(session, Pong.valueOf(TimeUtils.now()), null);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ClientIdleHandler extends ChannelDuplexHandler {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ClientIdleHandler.class);
|
||||
|
||||
private static final EncodedPacketInfo heartbeatPacket = EncodedPacketInfo.valueOf(Heartbeat.getInstance(), null);
|
||||
private static final EncodedPacketInfo heartbeatPacket = EncodedPacketInfo.valueOf(new Heartbeat(), null);
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
|
||||
|
||||
@@ -23,18 +23,9 @@ public class Heartbeat implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 102;
|
||||
|
||||
private static Heartbeat INSTANCE = new Heartbeat();
|
||||
|
||||
public static Heartbeat getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
public static short heartbeatProtocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,10 +23,6 @@ public class Ping implements IPacket {
|
||||
|
||||
public static final transient short PROTOCOL_ID = 103;
|
||||
|
||||
public static short pingProtocolId() {
|
||||
return PROTOCOL_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short protocolId() {
|
||||
return PROTOCOL_ID;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class Router implements IRouter {
|
||||
|
||||
@Override
|
||||
public void receive(Session session, IPacket packet, @Nullable IAttachment attachment) {
|
||||
if (packet.protocolId() == Heartbeat.heartbeatProtocolId()) {
|
||||
if (packet.protocolId() == Heartbeat.PROTOCOL_ID) {
|
||||
logger.info("heartbeat");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user