使用ChannelHandlerContext

This commit is contained in:
Guoqs
2024-08-01 11:51:27 +08:00
parent 3ac1d5752c
commit 0ad35c9300
3 changed files with 7 additions and 5 deletions

View File

@@ -26,7 +26,7 @@ public abstract class AbstractHandler implements InitializingBean {
* 执行逻辑
* 有应答
*/
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, Channel channel) {
public byte[] supplyProcess(YKCDataProtocol ykcDataProtocol, ChannelHandlerContext ctx) {
throw new UnsupportedOperationException();
}

View File

@@ -1,6 +1,7 @@
package com.jsowell.netty.service.electricbicycles;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
/**
@@ -12,10 +13,10 @@ public interface YKCBusinessService {
* 处理桩发来的请求
* 不需要应答的返回null
* @param msg 请求报文
* @param channel 通道信息
* @param ctx 通道信息
* @return 结果
*/
byte[] process(byte[] msg, Channel channel);
byte[] process(byte[] msg, ChannelHandlerContext ctx);
/**
* 桩退出

View File

@@ -14,6 +14,7 @@ import com.jsowell.pile.service.PileConnectorInfoService;
import com.jsowell.pile.service.PileMsgRecordService;
import com.jsowell.pile.service.YKCPushCommandService;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,7 +37,7 @@ public class YKCBusinessServiceImpl2 implements YKCBusinessService {
private YKCPushCommandService ykcPushCommandService;
@Override
public byte[] process(byte[] msg, Channel channel) {
public byte[] process(byte[] msg, ChannelHandlerContext ctx) {
if (!YKCUtils.checkMsg(msg)) {
// 校验不通过,丢弃消息
return null;
@@ -46,7 +47,7 @@ public class YKCBusinessServiceImpl2 implements YKCBusinessService {
String frameType = YKCUtils.frameType2Str(ykcDataProtocol.getFrameType());
// 获取业务处理handler
AbstractHandler invokeStrategy = YKCOperateFactory.getInvokeStrategy(frameType);
return invokeStrategy.supplyProcess(ykcDataProtocol, channel);
return invokeStrategy.supplyProcess(ykcDataProtocol, ctx);
}
@Override