|
@@ -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();
|