1. 增加Netty主动发送数据功能

This commit is contained in:
HuangXin 2023-08-08 23:20:08 +08:00
parent 48847965c1
commit cf42bfe56c
2 changed files with 17 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package com.zjyr.beidouservice.adapter.impl.netty; package com.zjyr.beidouservice.adapter.impl.netty;
import com.zjyr.beidouservice.misc.HelperUtils; import com.zjyr.beidouservice.misc.HelperUtils;
import com.zjyr.beidouservice.pojo.vo.ControlAdapterSocketCtx;
import com.zjyr.beidouservice.pojo.vo.YuanRongBinProtocol; import com.zjyr.beidouservice.pojo.vo.YuanRongBinProtocol;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -10,11 +11,15 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j @Slf4j
@Component @Component
@ChannelHandler.Sharable @ChannelHandler.Sharable
@RequiredArgsConstructor @RequiredArgsConstructor
public class MessageHandler extends SimpleChannelInboundHandler<YuanRongBinProtocol> { public class MessageHandler extends SimpleChannelInboundHandler<YuanRongBinProtocol> {
public static ConcurrentHashMap<Long, ControlAdapterSocketCtx> ctxMap = new ConcurrentHashMap<>();
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
log.info("{}:: Trigger Heart Signle", ctx.channel().id()); log.info("{}:: Trigger Heart Signle", ctx.channel().id());

View File

@ -0,0 +1,12 @@
package com.zjyr.beidouservice.pojo.vo;
import io.netty.channel.ChannelHandlerContext;
import lombok.Data;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor
public class ControlAdapterSocketCtx {
private Long controlAdapterId;
private ChannelHandlerContext ctx;
}