Class IdleStateHandlerNoUnvoid

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.infinispan.client.hotrod.impl.transport.netty.IdleStateHandlerNoUnvoid
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class IdleStateHandlerNoUnvoid extends io.netty.channel.ChannelDuplexHandler
Triggers an IdleStateEvent when a Channel has not performed read, write, or both operation for a while.

Supported idle states

PropertyMeaning
readerIdleTime an IdleStateEvent whose state is IdleState.READER_IDLE will be triggered when no read was performed for the specified period of time. Specify 0 to disable.
writerIdleTime an IdleStateEvent whose state is IdleState.WRITER_IDLE will be triggered when no write was performed for the specified period of time. Specify 0 to disable.
allIdleTime an IdleStateEvent whose state is IdleState.ALL_IDLE will be triggered when neither read nor write was performed for the specified period of time. Specify 0 to disable.
 // An example that sends a ping message when there is no outbound traffic
 // for 30 seconds.  The connection is closed when there is no inbound traffic
 // for 60 seconds.

 public class MyChannelInitializer extends ChannelInitializer<Channel> {
     @Override
     public void initChannel(Channel channel) {
         channel.pipeline().addLast("idleStateHandler", new IdleStateHandler(60, 30, 0));
         channel.pipeline().addLast("myHandler", new MyHandler());
     }
 }

 // Handler should handle the IdleStateEvent triggered by IdleStateHandler.
 public class MyHandler extends ChannelDuplexHandler {
     @Override
     public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
         if (evt instanceof IdleStateEvent) {
             IdleStateEvent e = (IdleStateEvent) evt;
             if (e.state() == IdleState.READER_IDLE) {
                 ctx.close();
             } else if (e.state() == IdleState.WRITER_IDLE) {
                 ctx.writeAndFlush(new PingMessage());
             }
         }
     }
 }

 ServerBootstrap bootstrap = ...;
 ...
 bootstrap.childHandler(new MyChannelInitializer());
 ...
 
See Also:
  • ReadTimeoutHandler
  • WriteTimeoutHandler
  • Nested Class Summary

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

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

    Constructors
    Constructor
    Description
    IdleStateHandlerNoUnvoid(boolean observeOutput, long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit)
    Creates a new instance firing IdleStateEvents.
    IdleStateHandlerNoUnvoid(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds)
    Creates a new instance firing IdleStateEvents.
    IdleStateHandlerNoUnvoid(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     
    protected void
    channelIdle(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.timeout.IdleStateEvent evt)
    Is called when an IdleStateEvent should be fired.
    void
    channelInactive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
     
    void
    channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelRegistered(io.netty.channel.ChannelHandlerContext ctx)
     
    long
    Return the allIdleTime that was given when instance this class in milliseconds.
    long
    Return the readerIdleTime that was given when instance this class in milliseconds.
    long
    Return the writerIdleTime that was given when instance this class in milliseconds.
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
     
    protected io.netty.handler.timeout.IdleStateEvent
    newIdleStateEvent(io.netty.handler.timeout.IdleState state, boolean first)
    Returns a IdleStateEvent.
    void
    Reset the read timeout.
    void
    Reset the write timeout.
    void
    write(io.netty.channel.ChannelHandlerContext ctx, 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

    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
  • Constructor Details

    • IdleStateHandlerNoUnvoid

      public IdleStateHandlerNoUnvoid(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds)
      Creates a new instance firing IdleStateEvents.
      Parameters:
      readerIdleTimeSeconds - an IdleStateEvent whose state is IdleState.READER_IDLE will be triggered when no read was performed for the specified period of time. Specify 0 to disable.
      writerIdleTimeSeconds - an IdleStateEvent whose state is IdleState.WRITER_IDLE will be triggered when no write was performed for the specified period of time. Specify 0 to disable.
      allIdleTimeSeconds - an IdleStateEvent whose state is IdleState.ALL_IDLE will be triggered when neither read nor write was performed for the specified period of time. Specify 0 to disable.
    • IdleStateHandlerNoUnvoid

      public IdleStateHandlerNoUnvoid(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit)
      See Also:
    • IdleStateHandlerNoUnvoid

      public IdleStateHandlerNoUnvoid(boolean observeOutput, long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit)
      Creates a new instance firing IdleStateEvents.
      Parameters:
      observeOutput - whether or not the consumption of bytes should be taken into consideration when assessing write idleness. The default is false.
      readerIdleTime - an IdleStateEvent whose state is IdleState.READER_IDLE will be triggered when no read was performed for the specified period of time. Specify 0 to disable.
      writerIdleTime - an IdleStateEvent whose state is IdleState.WRITER_IDLE will be triggered when no write was performed for the specified period of time. Specify 0 to disable.
      allIdleTime - an IdleStateEvent whose state is IdleState.ALL_IDLE will be triggered when neither read nor write was performed for the specified period of time. Specify 0 to disable.
      unit - the TimeUnit of readerIdleTime, writeIdleTime, and allIdleTime
  • Method Details

    • getReaderIdleTimeInMillis

      public long getReaderIdleTimeInMillis()
      Return the readerIdleTime that was given when instance this class in milliseconds.
    • getWriterIdleTimeInMillis

      public long getWriterIdleTimeInMillis()
      Return the writerIdleTime that was given when instance this class in milliseconds.
    • getAllIdleTimeInMillis

      public long getAllIdleTimeInMillis()
      Return the allIdleTime that was given when instance this class in milliseconds.
    • handlerAdded

      public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
      Throws:
      Exception
    • handlerRemoved

      public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      handlerRemoved in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerRemoved in class io.netty.channel.ChannelHandlerAdapter
      Throws:
      Exception
    • channelRegistered

      public void channelRegistered(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelRegistered in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRegistered in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • channelRead

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

      public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelReadComplete in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelReadComplete in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • write

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

      public void resetReadTimeout()
      Reset the read timeout. As this handler is not thread-safe, this method must be called on the event loop.
    • resetWriteTimeout

      public void resetWriteTimeout()
      Reset the write timeout. As this handler is not thread-safe, this method must be called on the event loop.
    • channelIdle

      protected void channelIdle(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.timeout.IdleStateEvent evt) throws Exception
      Is called when an IdleStateEvent should be fired. This implementation calls ChannelHandlerContext.fireUserEventTriggered(Object).
      Throws:
      Exception
    • newIdleStateEvent

      protected io.netty.handler.timeout.IdleStateEvent newIdleStateEvent(io.netty.handler.timeout.IdleState state, boolean first)
      Returns a IdleStateEvent.