Class NettyChannelUtil

java.lang.Object
org.apache.pulsar.common.util.netty.NettyChannelUtil

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

    • writeAndFlushWithVoidPromise

      public static void writeAndFlushWithVoidPromise(io.netty.channel.ChannelOutboundInvoker ctx, io.netty.buffer.ByteBuf 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, io.netty.buffer.ByteBuf 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