Class NettyChannelUtil


  • public final class NettyChannelUtil
    extends java.lang.Object
    Contains utility methods for working with Netty Channels.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void writeAndFlushWithClosePromise​(io.netty.channel.ChannelOutboundInvoker ctx, java.lang.Object msg)
      Write and flush the message to the channel and the close the channel.
      static void writeAndFlushWithVoidPromise​(io.netty.channel.ChannelOutboundInvoker ctx, java.lang.Object msg)
      Write and flush the message to the channel.
      • Methods inherited from class java.lang.Object

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

      • writeAndFlushWithVoidPromise

        public static void writeAndFlushWithVoidPromise​(io.netty.channel.ChannelOutboundInvoker ctx,
                                                        java.lang.Object msg)
        Write and flush the message to the channel. The promise is an instance of VoidChannelPromise that properly propagates exceptions up to the pipeline. Netty has many ad-hoc optimization if the promise is an instance of VoidChannelPromise. Lastly, it reduces pollution of useless ChannelPromise objects created by the default write and flush method ChannelOutboundInvoker.writeAndFlush(Object). See https://stackoverflow.com/q/54169262 and https://stackoverflow.com/a/9030420 for more details.
        Parameters:
        ctx - channel's context
        msg - buffer to write in the channel
      • writeAndFlushWithClosePromise

        public static void writeAndFlushWithClosePromise​(io.netty.channel.ChannelOutboundInvoker ctx,
                                                         java.lang.Object msg)
        Write and flush the message to the channel and the close the channel. This method is particularly helpful when the connection is in an invalid state and therefore a new connection must be created to continue.
        Parameters:
        ctx - channel's context
        msg - buffer to write in the channel