- 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
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(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 void
channelInactive(io.netty5.channel.ChannelHandlerContext ctx)
void
channelWritabilityChanged(io.netty5.channel.ChannelHandlerContext ctx)
void
flush(io.netty5.channel.ChannelHandlerContext ctx)
void
handlerAdded(io.netty5.channel.ChannelHandlerContext ctx)
void
resumeTransfer()
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:
handlerAdded
in 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:
write
in interfaceio.netty5.channel.ChannelHandler
-
flush
public void flush(io.netty5.channel.ChannelHandlerContext ctx)
- Specified by:
flush
in interfaceio.netty5.channel.ChannelHandler
-
channelInactive
public void channelInactive(io.netty5.channel.ChannelHandlerContext ctx) throws Exception
- Specified by:
channelInactive
in interfaceio.netty5.channel.ChannelHandler
- Throws:
Exception
-
-