|
@@ -2,7 +2,9 @@ package com.gzlh.background.client;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.gzlh.background.properties.BackgroundPropertiesConfig;
|
|
import com.gzlh.background.properties.BackgroundPropertiesConfig;
|
|
-import com.gzlh.event.EventBus;
|
|
|
|
|
|
+import com.gzlh.bus.EventBus;
|
|
|
|
+import com.gzlh.bus.EventDataManager;
|
|
|
|
+import com.gzlh.config.SystemObject;
|
|
import com.gzlh.utils.DeviceCache;
|
|
import com.gzlh.utils.DeviceCache;
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
@@ -31,15 +33,16 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
|
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
|
|
-// System.out.println("Client received: " + msg);
|
|
|
|
- if (!"Heartbeat".equalsIgnoreCase(msg)){
|
|
|
|
- eventBus.start(msg);
|
|
|
|
- }
|
|
|
|
|
|
+ System.out.println("Client received: " + msg);
|
|
|
|
+// if (!"back message".equalsIgnoreCase(msg)){
|
|
|
|
+// eventBus.startEvent(msg);
|
|
|
|
+// }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void sendHeartbeat(ChannelHandlerContext context) {
|
|
protected void sendHeartbeat(ChannelHandlerContext context) {
|
|
// 向后台发送设备信息json字符串
|
|
// 向后台发送设备信息json字符串
|
|
|
|
+ DeviceCache.add("channelCode", SystemObject.applicationConfig.getChannelCode());
|
|
String jsonStr = JSONUtil.toJsonStr(DeviceCache.getCacheMap());
|
|
String jsonStr = JSONUtil.toJsonStr(DeviceCache.getCacheMap());
|
|
context.writeAndFlush(jsonStr);
|
|
context.writeAndFlush(jsonStr);
|
|
// System.out.println(" sent ping msg to " + context.channel().remoteAddress());
|
|
// System.out.println(" sent ping msg to " + context.channel().remoteAddress());
|
|
@@ -74,6 +77,7 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
|
|
protected void handleWriterIdle(ChannelHandlerContext ctx) {
|
|
protected void handleWriterIdle(ChannelHandlerContext ctx) {
|
|
//写空闲时发送心跳包
|
|
//写空闲时发送心跳包
|
|
sendHeartbeat(ctx);
|
|
sendHeartbeat(ctx);
|
|
|
|
+
|
|
// System.err.println("---WRITER_IDLE---");
|
|
// System.err.println("---WRITER_IDLE---");
|
|
}
|
|
}
|
|
|
|
|