handler]netty之idle handler处理
初始化时记录idle时间,并启动一个延时任务,延时时间为idle时间,延时任务是io.netty.handler.timeout.IdleStateHandler.AllIdleTimeoutTask
channelReadComplete 会更新lastReadTime,lastWriteTime是在write操作返回的ChannelFuture实例上挂上listener监听operationComplete动作来更新的,详细参见io.netty.handler.timeout.IdleStateHandler.writeListener
AllIdleTimeoutTask 任务逻辑中会取lastReadTime, lastWriteTime大值,并拿nextDelay减去他们,这样就能得到下次任务要延期多就检查执行。
比如一开始是10:00,5分钟idle时间,那么会在10:05时检查(延迟5分钟),如果在10:04发生了读写,那么在10:05检查时算出下一次延迟启动任务是4分钟后即10:09分。
读写超时是基于此做的事件,检查机制类似。
且在netty4中未使用 HashedWheelTimer,而是在线NioEventLoop的spin loop中完成触发。在spin loop中会从io.netty.util.concurrent.AbstractScheduledEventExecutor.scheduledTaskQueue中peek出最前面(也是最早到达的定时任务)的看其deadline是否小于当前时间,如果是则执行。
HashedWheelTimer是在netty3中用来做idle检测的。
[netty4][netty-handler]netty之idle handler处理
,温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/41646.html
- 上一篇:多页面网站禁用浏览器后退键
- 下一篇:NodeJS+Koa2 实现书籍详情接口