Class ConnectTTLHandler

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

    public class ConnectTTLHandler
    extends io.netty.channel.ChannelDuplexHandler
    A handler that will close channels after they have reached their time-to-live, regardless of usage. channels that are in use will be closed when they are next released to the underlying connection pool.
    • Nested Class Summary

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

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

      Fields 
      Modifier and Type Field Description
      static io.netty.util.AttributeKey<java.lang.Boolean> RELEASE_CHANNEL  
    • Constructor Summary

      Constructors 
      Constructor Description
      ConnectTTLHandler​(java.lang.Long connectionTtlMillis)
      Construct ConnectTTLHandler for given arguments.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)
      Will schedule a task when the handler added.
      void handlerRemoved​(io.netty.channel.ChannelHandlerContext ctx)
      Will cancel the scheduled tasks when handler removed.
      static boolean isChannelExpired​(io.netty.channel.Channel channel)
      Indicates whether the channels connection ttl has expired.
      • 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, userEventTriggered
      • Methods inherited from class io.netty.channel.ChannelHandlerAdapter

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

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • RELEASE_CHANNEL

        public static final io.netty.util.AttributeKey<java.lang.Boolean> RELEASE_CHANNEL
    • Constructor Detail

      • ConnectTTLHandler

        public ConnectTTLHandler​(java.lang.Long connectionTtlMillis)
        Construct ConnectTTLHandler for given arguments.
        Parameters:
        connectionTtlMillis - The configured connect-ttl
    • Method Detail

      • handlerAdded

        public void handlerAdded​(io.netty.channel.ChannelHandlerContext ctx)
                          throws java.lang.Exception
        Will schedule a task when the handler added.
        Specified by:
        handlerAdded in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerAdded in class io.netty.channel.ChannelHandlerAdapter
        Parameters:
        ctx - The context to use
        Throws:
        java.lang.Exception
      • handlerRemoved

        public void handlerRemoved​(io.netty.channel.ChannelHandlerContext ctx)
        Will cancel the scheduled tasks when handler removed.
        Specified by:
        handlerRemoved in interface io.netty.channel.ChannelHandler
        Overrides:
        handlerRemoved in class io.netty.channel.ChannelHandlerAdapter
        Parameters:
        ctx - The context to use
      • isChannelExpired

        public static boolean isChannelExpired​(io.netty.channel.Channel channel)
        Indicates whether the channels connection ttl has expired.
        Parameters:
        channel - The channel to check
        Returns:
        true if the channels ttl has expired