Package org.apache.bookkeeper.util
Class NettyChannelUtil
- java.lang.Object
-
- org.apache.bookkeeper.util.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.
-
-
-
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 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, 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 contextmsg
- buffer to write in the channel
-
-