- java.lang.Object
-
- io.netty5.handler.stream.ChunkedWriteHandler
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class ChunkedWriteHandler extends Object implements io.netty5.channel.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(io.netty5.channel.ChannelHandlerContext ctx)voidchannelWritabilityChanged(io.netty5.channel.ChannelHandlerContext ctx)voidflush(io.netty5.channel.ChannelHandlerContext ctx)voidhandlerAdded(io.netty5.channel.ChannelHandlerContext ctx)voidresumeTransfer()Continues to fetch the chunks from the input.io.netty5.util.concurrent.Future<Void>write(io.netty5.channel.ChannelHandlerContext ctx, Object msg)-
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(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
resumeTransfer
public void resumeTransfer()
Continues to fetch the chunks from the input.
-
write
public io.netty5.util.concurrent.Future<Void> write(io.netty5.channel.ChannelHandlerContext ctx, Object msg)
- Specified by:
writein interfaceio.netty5.channel.ChannelHandler
-
flush
public void flush(io.netty5.channel.ChannelHandlerContext ctx)
- Specified by:
flushin interfaceio.netty5.channel.ChannelHandler
-
channelInactive
public void channelInactive(io.netty5.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelInactivein interfaceio.netty5.channel.ChannelHandler- Throws:
Exception
-
-