Class NettyChunkedWriteHandler
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- com.linkedin.venice.router.streaming.NettyChunkedWriteHandler
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler
,io.netty.channel.ChannelInboundHandler
,io.netty.channel.ChannelOutboundHandler
- Direct Known Subclasses:
VeniceChunkedWriteHandler
public class NettyChunkedWriteHandler extends io.netty.channel.ChannelDuplexHandler
This class was copied fromChunkedWriteHandler
, and the only change we made here is to usingConcurrentLinkedQueue
forqueue
sinceresumeTransfer()
ordiscard(Throwable)
could happen in any sequence with any parallelism because of scatter/gather logic in Venice Router. TODO: sync up with Netty team to see whether we could incorporate this change into Netty code base or not. Original Javadoc starts from here: AChannelHandler
that adds support for writing a large data stream asynchronously neither spending a lot of memory nor gettingOutOfMemoryError
. Large data streaming such as file transfer requires complicated state management in aChannelHandler
implementation.ChunkedWriteHandler
manages such complicated states so that you can send a large data stream without difficulties.To use
ChunkedWriteHandler
in your application, you have to insert a newChunkedWriteHandler
instance:ChannelPipeline
p = ...; p.addLast("streamer", newChunkedWriteHandler
()); p.addLast("handler", new MyHandler());ChunkedInput
so that theChunkedWriteHandler
can pick it up and fetch the content of the stream chunk by chunk and write the fetched chunk downstream:Channel
ch = ...; ch.write(newChunkedFile
(new File("video.mkv"));Sending a stream which generates a chunk intermittently
SomeChunkedInput
generates a chunk on a certain event or timing. SuchChunkedInput
implementation often returnsnull
onChunkedInput.readChunk(ChannelHandlerContext)
, resulting in the indefinitely suspended transfer. To resume the transfer when a new chunk is available, you have to callresumeTransfer()
.
-
-
Constructor Summary
Constructors Constructor Description NettyChunkedWriteHandler()
NettyChunkedWriteHandler(int maxPendingWrites)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
channelInactive(io.netty.channel.ChannelHandlerContext ctx)
void
channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx)
void
flush(io.netty.channel.ChannelHandlerContext ctx)
void
handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
void
resumeTransfer()
Continues to fetch the chunks from the input.void
write(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise)
-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, read
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerRemoved, isSharable
-
-
-
-
Method Detail
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
handlerAdded
in interfaceio.netty.channel.ChannelHandler
- Overrides:
handlerAdded
in classio.netty.channel.ChannelHandlerAdapter
- Throws:
java.lang.Exception
-
resumeTransfer
public void resumeTransfer()
Continues to fetch the chunks from the input.
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object msg, io.netty.channel.ChannelPromise promise) throws java.lang.Exception
- Specified by:
write
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
write
in classio.netty.channel.ChannelDuplexHandler
- Throws:
java.lang.Exception
-
flush
public void flush(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
flush
in interfaceio.netty.channel.ChannelOutboundHandler
- Overrides:
flush
in classio.netty.channel.ChannelDuplexHandler
- Throws:
java.lang.Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelInactive
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelInactive
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(io.netty.channel.ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
channelWritabilityChanged
in interfaceio.netty.channel.ChannelInboundHandler
- Overrides:
channelWritabilityChanged
in classio.netty.channel.ChannelInboundHandlerAdapter
- Throws:
java.lang.Exception
-
-