985653680@qq.com преди 1 година
родител
ревизия
2a20e2dfc9

+ 24 - 1
src/main/java/com/gzlh/background/client/BackgroundClientHandler.java

@@ -1,8 +1,9 @@
 package com.gzlh.background.client;
 
-import com.gzlh.socket.CustomHeartbeatHandler;
+import com.gzlh.background.client.CustomHeartbeatHandler;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.timeout.IdleStateEvent;
 import lombok.extern.slf4j.Slf4j;
 
 @Slf4j
@@ -57,6 +58,28 @@ public class BackgroundClientHandler extends CustomHeartbeatHandler {
 //    }
 
     @Override
+    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
+        // IdleStateHandler 所产生的 IdleStateEvent 的处理逻辑.
+        if (evt instanceof IdleStateEvent) {
+            IdleStateEvent e = (IdleStateEvent) evt;
+            switch (e.state()) {
+                case READER_IDLE:
+                    handleReaderIdle(ctx);
+                    break;
+                case WRITER_IDLE:
+                    handleWriterIdle(ctx);
+                    break;
+                case ALL_IDLE:
+                    handleAllIdle(ctx);
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+
+
+    @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
         cause.printStackTrace();
         ctx.close();

+ 14 - 0
src/main/java/com/gzlh/background/properties/BackgroundPropertiesConfig.java

@@ -0,0 +1,14 @@
+package com.gzlh.background.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@ConfigurationProperties(prefix = "background")
+@Configuration
+@Data
+public class BackgroundPropertiesConfig {
+    private String host;
+    private int port;
+    private boolean enable;
+}