mirror of
https://gitee.com/wujiawei1207537021/wu-lazy-cloud-network.git
synced 2026-02-04 15:05:54 +08:00
[fix] clean no use code
This commit is contained in:
@@ -8,13 +8,12 @@ import io.netty.handler.timeout.IdleStateEvent;
|
||||
import java.util.Date;
|
||||
|
||||
public class HeartBeatClientHandler extends ChannelInboundHandlerAdapter {
|
||||
private int lossConnectCount = 0;
|
||||
private final int lossConnectCount = 0;
|
||||
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||
System.out.println("客户端循环心跳监测发送: " + new Date());
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
if (evt instanceof IdleStateEvent event) {
|
||||
if (event.state() == IdleState.WRITER_IDLE) {
|
||||
ctx.writeAndFlush("biubiu");
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
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.ChannelHandlerContext;
|
||||
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.IdleStateEvent;
|
||||
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.util.Date;
|
||||
@@ -91,8 +91,7 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<NettyProxyMs
|
||||
*/
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
|
||||
if (obj instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) obj;
|
||||
if (obj instanceof IdleStateEvent event) {
|
||||
if (IdleState.WRITER_IDLE.equals(event.state())) { //如果写通道处于空闲状态,就发送心跳命令
|
||||
String clientId = nettyClientSocket.getClientId();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
|
||||
@@ -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.response.Result;
|
||||
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.MessageType;
|
||||
import wu.framework.lazy.cloud.heartbeat.common.NettyProxyMsg;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,9 +30,9 @@ public class StagingNoticeApiRpc {
|
||||
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_OPENED);
|
||||
nettyMsg.setData((clientId.toString()
|
||||
nettyMsg.setData((clientId
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
nettyMsg.setClientId((clientId.toString()
|
||||
nettyMsg.setClientId((clientId
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
channel.writeAndFlush(nettyMsg);
|
||||
}
|
||||
@@ -54,9 +53,9 @@ public class StagingNoticeApiRpc {
|
||||
Channel channel = clientChannel.getChannel();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.REPORT_CLIENT_STAGING_CLOSED);
|
||||
nettyMsg.setData((clientId.toString()
|
||||
nettyMsg.setData((clientId
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
nettyMsg.setClientId((clientId.toString()
|
||||
nettyMsg.setClientId((clientId
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
channel.writeAndFlush(nettyMsg);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ServerHandleClientConnectSuccessTypeAdvanced extends AbstractHandle
|
||||
Channel channel = clientChannel.getChannel();
|
||||
NettyProxyMsg nettyMsg = new NettyProxyMsg();
|
||||
nettyMsg.setType(MessageType.DISTRIBUTE_CLIENT_CONNECTION_SUCCESS_NOTIFICATION);
|
||||
nettyMsg.setData((JSON.toJSONString(clientIdList).toString()
|
||||
nettyMsg.setData((JSON.toJSONString(clientIdList)
|
||||
.getBytes(StandardCharsets.UTF_8)));
|
||||
// 发送所有客户端ID
|
||||
channel.writeAndFlush(nettyMsg);
|
||||
|
||||
@@ -18,8 +18,7 @@ public class HeartBeatServerHandler extends ChannelInboundHandlerAdapter {
|
||||
System.out.println("channelAttributeTenantId:" + channelAttributeId);
|
||||
System.out.println("已经5秒未收到客户端的消息了!");
|
||||
|
||||
if (evt instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) evt;
|
||||
if (evt instanceof IdleStateEvent event) {
|
||||
if (event.state() == IdleState.READER_IDLE) {
|
||||
lossConnectCount++;
|
||||
if (lossConnectCount > 2) {
|
||||
|
||||
@@ -54,8 +54,7 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<NettyProxyMs
|
||||
@Override
|
||||
public void userEventTriggered(ChannelHandlerContext ctx, Object obj) throws Exception {
|
||||
Channel channel = ctx.channel();
|
||||
if (obj instanceof IdleStateEvent) {
|
||||
IdleStateEvent event = (IdleStateEvent) obj;
|
||||
if (obj instanceof IdleStateEvent event) {
|
||||
if (IdleState.READER_IDLE.equals(event.state())) { //如果读通道处于空闲状态,说明没有接收到心跳命令
|
||||
String clientId = ChannelAttributeKeyUtils.getClientId(channel);
|
||||
String visitorId = ChannelAttributeKeyUtils.getVisitorId(channel);
|
||||
|
||||
Reference in New Issue
Block a user