public class ChunkedReadWriteHandler extends io.netty.handler.stream.ChunkedWriteHandler
ChunkedWriteHandler only handles the down stream parts and just emits the chunks up stream. So we add an upstream handler that aggregates the chunks into its original form. This is guaranteed to be thread serial so state can be shared.
On the down stream side, we just decorate the original message with its size and allow the thread-serial base class to actually handle the chunking. We need to be careful since the decoration itself has to be thread-safe since netty does not guarantee thread serial access to down stream handlers.
We do not need to tag the writes since the base class ChunkedWriteHandler serializes access to the channel and first write will complete before the second begins.
Modifier and Type | Field and Description |
---|---|
static int |
INT_SIZE |
Constructor and Description |
---|
ChunkedReadWriteHandler() |
Modifier and Type | Method and Description |
---|---|
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise)
Thread-safe since there is no shared instance state.
|
channelInactive, channelWritabilityChanged, flush, handlerAdded, resumeTransfer
bind, close, connect, deregister, disconnect, read
channelActive, channelReadComplete, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
public static final int INT_SIZE
public ChunkedReadWriteHandler()
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
org.jboss.netty.handler.stream.ChunkedWriteHandler#handleUpstream(
org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
We do not need to tag the writes since the base class ChunkedWriteHandler serializes access to the channel and first write will complete before the second begins.
write
in interface io.netty.channel.ChannelOutboundHandler
write
in class io.netty.handler.stream.ChunkedWriteHandler
Exception
Copyright © 2017 The Apache Software Foundation. All rights reserved.