| | |
| | | @Override |
| | | protected void initChannel(SocketChannel socketChannel) { |
| | | ChannelPipeline pipeline = socketChannel.pipeline(); |
| | | pipeline.addLast("heart", new IdleStateHandler(0, 3, 0, TimeUnit.SECONDS)); |
| | | pipeline.addLast("heart", new IdleStateHandler(0, 5, 0, TimeUnit.SECONDS)); |
| | | pipeline.addLast("encoder", new MessageProtocolEncoder()); |
| | | pipeline.addLast("decoder", new MessageProtocolDecoder()); |
| | | pipeline.addLast("handler", clientHandler); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 定时向所有已连接的六合服务器发送心跳 |
| | | * 定时向所有已连接的边缘服务器服务器发送心跳(写空闲已经发心跳了,这里暂时取消) |
| | | */ |
| | | @Scheduled(fixedRate = 5000) // 每5秒执行一次 |
| | | // @Scheduled(fixedRate = 5000) // 每5秒执行一次 |
| | | public void sendHeartBeat() { |
| | | long timestamp = System.currentTimeMillis(); |
| | | TyTcpServerCache.getChannels().stream() |
| | |
| | | String serverId = (String) channel.attr(AttributeKey.valueOf("serverId")).get(); |
| | | HeartbeatCmd heartbeat = new HeartbeatCmd(timestamp); |
| | | channel.writeAndFlush(heartbeat); |
| | | log.info("→ 向边缘服务器 [{}]发送心跳,时间戳={}", serverId, timestamp); |
| | | log.info("❤\uFE0F 向边缘服务器 [{}]发送心跳,时间戳={}", serverId, timestamp); |
| | | }); |
| | | } |
| | | } |