Merge branch 'dev-new' into dev-new-rabbitmq

This commit is contained in:
Guoqs
2024-12-30 10:12:15 +08:00
3 changed files with 22 additions and 28 deletions

View File

@@ -4,7 +4,6 @@ import com.jsowell.common.constant.Constants;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
import java.nio.charset.StandardCharsets;
@@ -136,9 +135,9 @@ public class YouDianProtocolDecoder extends ByteToMessageDecoder {
buffer.readerIndex(beginReader + HEADER_LENGTH_DNY + length + 2);
out.add(frame);
} finally {
if (frame != null) {
ReferenceCountUtil.release(frame);
}
// if (frame != null) {
// ReferenceCountUtil.release(frame);
// }
}
}

View File

@@ -96,6 +96,7 @@ public class NettyServerManager implements CommandLineRunner {
.handler(new LoggingHandler(LogLevel.DEBUG))
.option(ChannelOption.SO_BACKLOG, 128)
.option(ChannelOption.SO_REUSEADDR, true)
// .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) // 启用池化内存分配器
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.SO_REUSEADDR, true)
.childHandler(electricBicyclesServerChannelInitializer)

View File

@@ -8,7 +8,6 @@ import com.jsowell.netty.service.electricbicycles.EBikeBusinessService;
import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.handler.timeout.ReadTimeoutException;
import io.netty.util.ReferenceCountUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -61,7 +60,6 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
try {
byte[] msg = (byte[]) message;
// 处理数据
byte[] response = eBikeService.process(msg, ctx);
@@ -81,10 +79,6 @@ public class ElectricBicyclesServerHandler extends ChannelInboundHandlerAdapter
// BytesUtil.binary(response, 16));
// }
}
} finally {
ReferenceCountUtil.release(message);
}
}
/**