mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 19:45:09 +08:00
同步获取响应数据
This commit is contained in:
@@ -6,6 +6,8 @@ import com.jsowell.common.enums.ykc.PileChannelEntity;
|
||||
import com.jsowell.common.util.BytesUtil;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.common.util.YKCUtils;
|
||||
import com.jsowell.netty.rpc.RpcUtil;
|
||||
import com.jsowell.pile.rpc.SyncPromise;
|
||||
import com.jsowell.netty.service.yunkuaichong.YKCBusinessService;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.*;
|
||||
@@ -28,7 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
@ChannelHandler.Sharable
|
||||
@Slf4j
|
||||
@Component
|
||||
public class NettyServerHandler extends SimpleChannelInboundHandler {
|
||||
public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@Autowired
|
||||
private YKCBusinessService ykcService;
|
||||
@@ -73,19 +75,29 @@ public class NettyServerHandler extends SimpleChannelInboundHandler {
|
||||
// 获取帧类型
|
||||
byte[] frameTypeBytes = BytesUtil.copyBytes(msg, 5, 1);
|
||||
String frameType = YKCUtils.frameType2Str(frameTypeBytes);
|
||||
|
||||
// 判断该帧类型是否为某请求帧的应答帧
|
||||
String requestFrameType = YKCFrameTypeCode.PileAnswersRelation.getRequestFrameType(frameType);
|
||||
if (StringUtils.isNotBlank(requestFrameType)) {
|
||||
// 根据请求id,在集合中找到与外部线程通信的SyncPromise对象
|
||||
String msgId = ctx.channel().id().toString() + "_" + requestFrameType;
|
||||
SyncPromise syncPromise = RpcUtil.getSyncPromiseMap().get(msgId);
|
||||
if(syncPromise != null) {
|
||||
// 设置响应结果
|
||||
syncPromise.setRpcResult(msg);
|
||||
// 唤醒外部线程
|
||||
syncPromise.wake();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取序列号域
|
||||
int serialNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(msg, 2, 2));
|
||||
|
||||
// 获取channel
|
||||
Channel channel = ctx.channel();
|
||||
|
||||
// new
|
||||
// String hexString = DatatypeConverter.printHexBinary(msg);
|
||||
|
||||
// 心跳包0x03日志太多,造成日志文件过大,改为不打印
|
||||
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
|
||||
// log.info("【<<<<<平台收到消息<<<<<】channel:{}, 帧类型:{}, 帧名称:{}, 序列号域:{}, 报文:{}, new报文:{}",
|
||||
// channel.id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
|
||||
// BytesUtil.binary(msg, 16), hexString);
|
||||
log.info("【<<<<<平台收到消息<<<<<】channel:{}, 帧类型:{}, 帧名称:{}, 序列号域:{}, 报文:{}",
|
||||
channel.id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
|
||||
BytesUtil.binary(msg, 16));
|
||||
@@ -109,10 +121,10 @@ public class NettyServerHandler extends SimpleChannelInboundHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
log.info("channelRead0=== channelId:" + ctx.channel().id() + ", msg:" + msg);
|
||||
}
|
||||
// @Override
|
||||
// protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
// log.info("channelRead0=== channelId:" + ctx.channel().id() + ", msg:" + msg);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 有客户端终止连接服务器会触发此函数
|
||||
|
||||
Reference in New Issue
Block a user