- java.lang.Object
-
- io.netty5.handler.stream.ChunkedWriteHandler
-
- All Implemented Interfaces:
ChannelHandler
public class ChunkedWriteHandler extends Object implements ChannelHandler
AChannelHandlerthat 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 aChannelHandlerimplementation.ChunkedWriteHandlermanages such complicated states so that you can send a large data stream without difficulties.To use
ChunkedWriteHandlerin your application, you have to insert a newChunkedWriteHandlerinstance:
Once inserted, you can write aChannelPipelinep = ...; p.addLast("streamer", newChunkedWriteHandler()); p.addLast("handler", new MyHandler());ChunkedInputso that theChunkedWriteHandlercan pick it up and fetch the content of the stream chunk by chunk and write the fetched chunk downstream:Channelch = ...; ch.write(newChunkedFile(new File("video.mkv"));Sending a stream which generates a chunk intermittently
SomeChunkedInputgenerates a chunk on a certain event or timing. SuchChunkedInputimplementation often returnsnullonChunkedInput.readChunk(BufferAllocator), 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 ChunkedWriteHandler()ChunkedWriteHandler(int maxPendingWrites)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchannelInactive(ChannelHandlerContext ctx)TheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.voidchannelWritabilityChanged(ChannelHandlerContext ctx)Gets called once the writable state of aChannelchanged.voidflush(ChannelHandlerContext ctx)Called once a flush operation is made.voidhandlerAdded(ChannelHandlerContext ctx)Gets called after theChannelHandlerwas added to the actual context and it's ready to handle events.voidresumeTransfer()Continues to fetch the chunks from the input.Future<Void>write(ChannelHandlerContext ctx, Object msg)Called once a write operation is made.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInboundEvent, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, close, connect, deregister, disconnect, handlerRemoved, isSharable, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Constructor Detail
-
ChunkedWriteHandler
public ChunkedWriteHandler()
-
ChunkedWriteHandler
@Deprecated public ChunkedWriteHandler(int maxPendingWrites)
Deprecated.
-
-
Method Detail
-
handlerAdded
public void handlerAdded(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called after theChannelHandlerwas added to the actual context and it's ready to handle events.- Specified by:
handlerAddedin interfaceChannelHandler- Throws:
Exception
-
resumeTransfer
public void resumeTransfer()
Continues to fetch the chunks from the input.
-
write
public Future<Void> write(ChannelHandlerContext ctx, Object msg)
Description copied from interface:ChannelHandlerCalled once a write operation is made. The write operation will write the messages through theChannelPipeline. Those are then ready to be flushed to the actualChannelonceChannel.flush()is called.- Specified by:
writein interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the write operation is mademsg- the message to write- Returns:
- the
Futurewhich will be notified once the operation completes.
-
flush
public void flush(ChannelHandlerContext ctx)
Description copied from interface:ChannelHandlerCalled once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.- Specified by:
flushin interfaceChannelHandler- Parameters:
ctx- theChannelHandlerContextfor which the flush operation is made
-
channelInactive
public void channelInactive(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerTheChannelof theChannelHandlerContextwas registered is now inactive and reached its end of lifetime.- Specified by:
channelInactivein interfaceChannelHandler- Throws:
Exception
-
channelWritabilityChanged
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception
Description copied from interface:ChannelHandlerGets called once the writable state of aChannelchanged. You can check the state withChannel.writableBytes()orChannel.isWritable().- Specified by:
channelWritabilityChangedin interfaceChannelHandler- Throws:
Exception
-
-