Class WriteTimeoutHandler

  • All Implemented Interfaces:
    io.netty5.channel.ChannelHandler

    public class WriteTimeoutHandler
    extends Object
    implements io.netty5.channel.ChannelHandler
    Raises a WriteTimeoutException when a write operation cannot finish in a certain period of time.
     // The connection is closed when a write operation cannot finish in 30 seconds.
    
     public class MyChannelInitializer extends ChannelInitializer<Channel> {
         public void initChannel(Channel channel) {
             channel.pipeline().addLast("writeTimeoutHandler", new WriteTimeoutHandler(30);
             channel.pipeline().addLast("myHandler", new MyHandler());
         }
     }
    
     // Handler should handle the WriteTimeoutException.
     public class MyHandler implements ChannelHandler {
         @Override
         public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
                 throws Exception {
             if (cause instanceof WriteTimeoutException) {
                 // do something
             } else {
                 super.exceptionCaught(ctx, cause);
             }
         }
     }
    
     ServerBootstrap bootstrap = ...;
     ...
     bootstrap.childHandler(new MyChannelInitializer());
     ...
     
    See Also:
    ReadTimeoutHandler, IdleStateHandler
    • Nested Class Summary

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

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void handlerRemoved​(io.netty5.channel.ChannelHandlerContext ctx)  
      io.netty5.util.concurrent.Future<Void> write​(io.netty5.channel.ChannelHandlerContext ctx, Object msg)  
      protected void writeTimedOut​(io.netty5.channel.ChannelHandlerContext ctx)
      Is called when a write timeout was detected
      • Methods inherited from interface io.netty5.channel.ChannelHandler

        bind, channelActive, channelInactive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, handlerAdded, read, register, userEventTriggered
    • Constructor Detail

      • WriteTimeoutHandler

        public WriteTimeoutHandler​(int timeoutSeconds)
        Creates a new instance.
        Parameters:
        timeoutSeconds - write timeout in seconds
      • WriteTimeoutHandler

        public WriteTimeoutHandler​(long timeout,
                                   TimeUnit unit)
        Creates a new instance.
        Parameters:
        timeout - write timeout
        unit - the TimeUnit of timeout
    • Method Detail

      • write

        public io.netty5.util.concurrent.Future<Void> write​(io.netty5.channel.ChannelHandlerContext ctx,
                                                            Object msg)
        Specified by:
        write in interface io.netty5.channel.ChannelHandler
      • handlerRemoved

        public void handlerRemoved​(io.netty5.channel.ChannelHandlerContext ctx)
                            throws Exception
        Specified by:
        handlerRemoved in interface io.netty5.channel.ChannelHandler
        Throws:
        Exception
      • writeTimedOut

        protected void writeTimedOut​(io.netty5.channel.ChannelHandlerContext ctx)
                              throws Exception
        Is called when a write timeout was detected
        Throws:
        Exception