Class MqttIdleStateHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.timeout.IdleStateHandler
com.bytedesk.core.socket.mqtt.handler.MqttIdleStateHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
public class MqttIdleStateHandler
extends io.netty.handler.timeout.IdleStateHandler
检测空闲连接和超时是为了及时释放资源: 在规定时间内没有收到来自客户端的任何packet,包括ping
常用的方法:
1. 发送消息用于测试一个不活跃的连接(俗称'心跳')到远程断点用来确定其是否还活着。
2. 另一种比较粗暴的方法是直接断开那些指定时间间隔内不活跃的连接
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable
-
Constructor Summary
ConstructorsConstructorDescriptionMqttIdleStateHandler
(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
channelIdle
(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.timeout.IdleStateEvent evt) Methods inherited from class io.netty.handler.timeout.IdleStateHandler
channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, getAllIdleTimeInMillis, getReaderIdleTimeInMillis, getWriterIdleTimeInMillis, handlerAdded, handlerRemoved, newIdleStateEvent, resetReadTimeout, resetWriteTimeout, write
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Constructor Details
-
MqttIdleStateHandler
public MqttIdleStateHandler(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds)
-
-
Method Details