Class StaleConnectionHandler

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

    public class StaleConnectionHandler
    extends io.netty.channel.ChannelDuplexHandler
    This handler closes the connection when a ReadTimeoutException occurs. Example:
     public class MyChannelInitializer extends ChannelInitializer<Channel> {
       public void initChannel(Channel channel) {
         channel.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(30, TimeUnit.SECONDS);
         channel.pipeline().addLast("staleConnectionHandler", new StaleConnectionHandler());
       }
     }
     
    • Nested Class Summary

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

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

      Constructors 
      Constructor Description
      StaleConnectionHandler()
      Create an EspressoIdleConnectionHandler which will close idle connections (detected by a separate IdleStateHandler added to the pipeline).
      StaleConnectionHandler​(long minCloseAge, long maxCloseAge, java.util.concurrent.TimeUnit unit)
      Deprecated.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void channelRead​(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg)  
      void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)
      Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline.
      boolean isStaleChannel()  
      void write​(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise)  
      • Methods inherited from class io.netty.channel.ChannelDuplexHandler

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

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

        ensureNotSharable, handlerAdded, handlerRemoved, isSharable
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Constructor Detail

      • StaleConnectionHandler

        public StaleConnectionHandler()
        Create an EspressoIdleConnectionHandler which will close idle connections (detected by a separate IdleStateHandler added to the pipeline).
      • StaleConnectionHandler

        @Deprecated
        public StaleConnectionHandler​(long minCloseAge,
                                      long maxCloseAge,
                                      java.util.concurrent.TimeUnit unit)
        Deprecated.
        Create an EspressoIdleConnectionHandler which will close idle connections (detected by a separate IdleStateHandler added to the pipeline), and will close non-idle connections after a specified time. Connections will be closed at a random time between minCloseAge and maxCloseAge.
        Parameters:
        minCloseAge - base age of an active connection before we terminate
        maxCloseAge - random offset, should be large enough to spread out closing time for multiple connections
        unit - TimeUnit for closeAfterAgeBase and closeAfterAgeRandom
    • Method Detail

      • isStaleChannel

        public boolean isStaleChannel()
      • exceptionCaught

        public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx,
                                    java.lang.Throwable cause)
                             throws java.lang.Exception
        Calls ChannelHandlerContext.fireExceptionCaught(Throwable) to forward to the next ChannelHandler in the ChannelPipeline.

        Sub-classes may override this method to change behavior.

        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelHandler
        Specified by:
        exceptionCaught in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
        Parameters:
        ctx -
        cause -
        Throws:
        java.lang.Exception
      • write

        public void write​(io.netty.channel.ChannelHandlerContext ctx,
                          java.lang.Object msg,
                          io.netty.channel.ChannelPromise promise)
                   throws java.lang.Exception
        Specified by:
        write in interface io.netty.channel.ChannelOutboundHandler
        Overrides:
        write in class io.netty.channel.ChannelDuplexHandler
        Throws:
        java.lang.Exception
      • channelRead

        public void channelRead​(io.netty.channel.ChannelHandlerContext ctx,
                                java.lang.Object msg)
                         throws java.lang.Exception
        Specified by:
        channelRead in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        java.lang.Exception