[fix] clean no use code

This commit is contained in:
wujiawei
2024-01-25 23:10:59 +08:00
parent 47b8dd68b3
commit 5894f6e18b
6 changed files with 15 additions and 20 deletions

View File

@@ -8,13 +8,12 @@ import io.netty.handler.timeout.IdleStateEvent;
import java.util.Date; import java.util.Date;
public class HeartBeatClientHandler extends ChannelInboundHandlerAdapter { public class HeartBeatClientHandler extends ChannelInboundHandlerAdapter {
private int lossConnectCount = 0; private final int lossConnectCount = 0;
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
System.out.println("客户端循环心跳监测发送: " + new Date()); System.out.println("客户端循环心跳监测发送: " + new Date());
if (evt instanceof IdleStateEvent) { if (evt instanceof IdleStateEvent event) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.WRITER_IDLE) { if (event.state() == IdleState.WRITER_IDLE) {
ctx.writeAndFlush("biubiu"); ctx.writeAndFlush("biubiu");
} }

View File

@@ -1,9 +1,5 @@
package wu.framework.lazy.cloud.heartbeat.client.netty.handler; package wu.framework.lazy.cloud.heartbeat.client.netty.handler;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
@@ -11,6 +7,10 @@ import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent; import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import wu.framework.lazy.cloud.heartbeat.client.netty.socket.NettyClientSocket;
import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import wu.framework.lazy.cloud.heartbeat.common.adapter.ChannelTypeAdapter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
@@ -91,8 +91,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
*/ */
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
if (obj instanceof IdleStateEvent) { if (obj instanceof IdleStateEvent event) {
IdleStateEvent event = (IdleStateEvent) obj;
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令 if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
String clientId = nettyClientSocket.getClientId(); String clientId = nettyClientSocket.getClientId();
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();

View File

@@ -3,12 +3,11 @@ package wu.framework.lazy.cloud.heartbeat.client.rpc;
import com.wu.framework.database.lazy.web.plus.stereotype.LazyRpc; import com.wu.framework.database.lazy.web.plus.stereotype.LazyRpc;
import com.wu.framework.response.Result; import com.wu.framework.response.Result;
import com.wu.framework.response.ResultFactory; import com.wu.framework.response.ResultFactory;
import io.netty.channel.Channel;
import wu.framework.lazy.cloud.heartbeat.common.ChannelContext; import wu.framework.lazy.cloud.heartbeat.common.ChannelContext;
import wu.framework.lazy.cloud.heartbeat.common.MessageType; import wu.framework.lazy.cloud.heartbeat.common.MessageType;
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg; import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
import io.netty.channel.Channel;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
@@ -31,9 +30,9 @@ public class StagingNoticeApiRpc {
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_OPENED); nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_OPENED);
nettyMsg.setData((clientId.toString() nettyMsg.setData((clientId
.getBytes(StandardCharsets.UTF_8))); .getBytes(StandardCharsets.UTF_8)));
nettyMsg.setClientId((clientId.toString() nettyMsg.setClientId((clientId
.getBytes(StandardCharsets.UTF_8))); .getBytes(StandardCharsets.UTF_8)));
channel.writeAndFlush(nettyMsg); channel.writeAndFlush(nettyMsg);
} }
@@ -54,9 +53,9 @@ public class StagingNoticeApiRpc {
Channel channel = clientChannel.getChannel(); Channel channel = clientChannel.getChannel();
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_CLOSED); nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_CLOSED);
nettyMsg.setData((clientId.toString() nettyMsg.setData((clientId
.getBytes(StandardCharsets.UTF_8))); .getBytes(StandardCharsets.UTF_8)));
nettyMsg.setClientId((clientId.toString() nettyMsg.setClientId((clientId
.getBytes(StandardCharsets.UTF_8))); .getBytes(StandardCharsets.UTF_8)));
channel.writeAndFlush(nettyMsg); channel.writeAndFlush(nettyMsg);
} }

View File

@@ -72,7 +72,7 @@ public class ServerHandleClientConnectSuccessTypeAdvanced extends AbstractHandle
Channel channel = clientChannel.getChannel(); Channel channel = clientChannel.getChannel();
NettyProxyMsg nettyMsg = new NettyProxyMsg(); NettyProxyMsg nettyMsg = new NettyProxyMsg();
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION); nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION);
nettyMsg.setData((JSON.toJSONString(clientIdList).toString() nettyMsg.setData((JSON.toJSONString(clientIdList)
.getBytes(StandardCharsets.UTF_8))); .getBytes(StandardCharsets.UTF_8)));
// 发送所有客户端ID // 发送所有客户端ID
channel.writeAndFlush(nettyMsg); channel.writeAndFlush(nettyMsg);

View File

@@ -18,8 +18,7 @@ public class HeartBeatServerHandler extends ChannelInboundHandlerAdapter {
System.out.println("channelAttributeTenantId:" + channelAttributeId); System.out.println("channelAttributeTenantId:" + channelAttributeId);
System.out.println("已经5秒未收到客户端的消息了"); System.out.println("已经5秒未收到客户端的消息了");
if (evt instanceof IdleStateEvent) { if (evt instanceof IdleStateEvent event) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.READER_IDLE) { if (event.state() == IdleState.READER_IDLE) {
lossConnectCount++; lossConnectCount++;
if (lossConnectCount > 2) { if (lossConnectCount > 2) {

View File

@@ -54,8 +54,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<NettyProxyMs
@Override @Override
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
Channel channel = ctx.channel(); Channel channel = ctx.channel();
if (obj instanceof IdleStateEvent) { if (obj instanceof IdleStateEvent event) {
IdleStateEvent event = (IdleStateEvent) obj;
if (IdleState.READER_IDLE.equals(event.state())) { //如果读通道处于空闲状态,说明没有接收到心跳命令 if (IdleState.READER_IDLE.equals(event.state())) { //如果读通道处于空闲状态,说明没有接收到心跳命令
String clientId = ChannelAttributeKeyUtils.getClientId(channel); String clientId = ChannelAttributeKeyUtils.getClientId(channel);
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel); String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);