update netty优化业务线程池

This commit is contained in:
Lemon
2025-07-22 16:23:18 +08:00
parent 1edab2a4aa
commit dda3751cda
2 changed files with 23 additions and 4 deletions

View File

@@ -27,5 +27,21 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter {
ctx.write(msg);
//刷新缓存区
ctx.flush();
// ByteBuf byteBuf = (ByteBuf) msg;
// ByteBuf byteBuf = Unpooled.copiedBuffer("680d01000004882300000001290100d510", StandardCharsets.UTF_8);
// // byteBuf.readBytes(bytes);
// YKCDataProtocol ykcDataProtocol = new YKCDataProtocol(new byte[]{});
//
// // 获取帧类型
// byte[] frameTypeBytes = ykcDataProtocol.getFrameType();
// String frameType = YKCUtils.frameType2Str(frameTypeBytes);
// // 获取序列号域
// int serialNumber = BytesUtil.bytesToIntLittle(ykcDataProtocol.getSerialNumber());
// if (!CollectionUtils.containsAny(NettyServerHandler.notPrintFrameTypeList, frameType)) {
// log.info("【>>>>>平台响应消息>>>>>】channel:{}, 响应帧类型:{}, 响应帧名称:{}, 序列号域:{}, response:{}",
// ctx.channel().id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
// BytesUtil.binary(ykcDataProtocol.getBytes(), 16));
// }
}
}

View File

@@ -8,6 +8,7 @@ import com.jsowell.common.util.BytesUtil;
import com.jsowell.common.util.StringUtils;
import com.jsowell.common.util.YKCUtils;
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
import com.jsowell.netty.service.yunkuaichong.impl.YKCBusinessServiceImpl;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.handler.timeout.IdleState;
@@ -19,6 +20,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Objects;
@@ -32,15 +34,17 @@ import java.util.concurrent.ConcurrentHashMap;
@Component
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
@Autowired
private YKCBusinessService ykcService;
// @Resource
// private YKCBusinessService ykcService;
/**
* 管理一个全局map保存连接进服务端的通道数量
*/
private static final ConcurrentHashMap<ChannelId, ChannelHandlerContext> CHANNEL_MAP = new ConcurrentHashMap<>();
private final List<String> notPrintFrameTypeList = Lists.newArrayList("0x03"); // "0x03"
protected static final List<String> notPrintFrameTypeList = Lists.newArrayList(); // "0x03"
private final YKCBusinessService ykcService = new YKCBusinessServiceImpl();
/**
* 有客户端连接服务器会触发此函数
@@ -150,7 +154,6 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
ByteBuf buffer = ctx.alloc().buffer().writeBytes(response);
// this.channelWrite(channel.id(), buffer);
super.channelRead(ctx, buffer);
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
// 应答帧类型
byte[] responseFrameTypeBytes = YKCFrameTypeCode.PlatformAnswersRelation.getResponseFrameTypeBytes(frameTypeBytes);