Class NettyIdleStateKeepAliveHandler

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

    public class NettyIdleStateKeepAliveHandler
    extends io.netty.channel.ChannelDuplexHandler
    A NettyIdleStateKeepAliveHandler listens for IdleStateEvents triggered by an IdleStateHandler. When invoked, the existence of a flag on the ChannelHandlerContext is determined. If this flag does not exist, then a keep-alive check if performed and the flag is set. If the does exist, then it is assumed that the peer failed the keep-alive check and the connection should be closed. The keep-alive check is implemented as an XMPP ping request. XMPP entities must respond with either an IQ result or an IQ error (feature-unavailable) stanza upon receiving the XMPP ping stanza. Both responses will be received by Openfire. As any inbound data will cause the flag to be reset, the connection will no longer be deemed 'idle'. Entities that do not respond to the IQ Ping stanzas can be considered dead, and their connection will be closed when the IdleStateHandler triggers the second idle event in a row. Note that whitespace pings that are sent by XMPP entities will also cause the connection idle count to be reset.
    Author:
    Alex Gidman
    See Also:
    IdleStateEvent, IdleStateHandler
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx, Object evt)
      Processes IdleStateEvents triggered by an IdleStateHandler.
      • Methods inherited from class io.netty.channel.ChannelDuplexHandler

        bind, close, connect, deregister, disconnect, flush, read, write
      • Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

        channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

        ensureNotSharable, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from interface io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Constructor Detail

      • NettyIdleStateKeepAliveHandler

        public NettyIdleStateKeepAliveHandler​(boolean clientConnection)
    • Method Detail

      • userEventTriggered

        public void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx,
                                       Object evt)
                                throws Exception
        Processes IdleStateEvents triggered by an IdleStateHandler. If the IdleStateEvent is an idle read state, the Netty channel is closed. If the IdleStateEvent is an idle write state, an XMPP ping request is sent to the remote entity.
        Specified by:
        userEventTriggered in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter
        Parameters:
        ctx - ChannelHandlerContext
        evt - Event caught, expect IdleStateEvent
        Throws:
        Exception - when attempting to deliver ping packet