Class NettyChannelUtil
java.lang.Object
org.apache.pulsar.common.util.netty.NettyChannelUtil
Contains utility methods for working with Netty Channels.
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static void
writeAndFlushWithVoidPromise
(io.netty.channel.ChannelOutboundInvoker ctx, io.netty.buffer.ByteBuf msg) Write and flush the message to the channel.
-
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 ofVoidChannelPromise
that properly propagates exceptions up to the pipeline. Netty has many ad-hoc optimization if the promise is an instance ofVoidChannelPromise
. Lastly, it reduces pollution of uselessChannelPromise
objects created by the default write and flush methodChannelOutboundInvoker.writeAndFlush(Object)
. See https://stackoverflow.com/q/54169262 and https://stackoverflow.com/a/9030420 for more details.- Parameters:
ctx
- channel's contextmsg
- 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 contextmsg
- buffer to write in the channel
-