ChannelHandler that adds support for writing a large data stream
asynchronously neither spending a lot of memory nor getting
OutOfMemoryError. Large data streaming such as file
transfer requires complicated state management in a ChannelHandler
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 new ChunkedWriteHandler instance:
Once inserted, you can write aChannelPipelinep = ...; p.addLast("streamer", newChunkedWriteHandler()); p.addLast("handler", new MyHandler());
ChunkedInput so that the
ChunkedWriteHandler can 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"));
ChunkedInput generates a chunk on a certain event or timing.
Such ChunkedInput implementation often returns null on
ChunkedInput#readChunk(ChannelHandlerContext), resulting in the indefinitely suspended
transfer. To resume the transfer when a new chunk is available, you have to
call resumeTransfer().
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private volatile ChannelHandlerContext | |
| private static final InternalLogger | |
| private Queue |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| ctx | back to summary |
|---|---|
| private volatile ChannelHandlerContext ctx | |
| logger | back to summary |
|---|---|
| private static final InternalLogger logger | |
| queue | back to summary |
|---|---|
| private Queue<ChunkedWriteHandler. | |
| ChunkedWriteHandler | back to summary |
|---|---|
| public ChunkedWriteHandler() | |
| ChunkedWriteHandler | back to summary |
|---|---|
| public ChunkedWriteHandler(int maxPendingWrites)
Deprecated
| |
| allocateQueue | back to summary |
|---|---|
| private void allocateQueue() | |
| channelInactive | back to summary |
|---|---|
| public void channelInactive(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| channelWritabilityChanged | back to summary |
|---|---|
| public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| closeInput | back to summary |
|---|---|
| private static void closeInput(ChunkedInput<?> chunks) | |
| discard | back to summary |
|---|---|
| private void discard(Throwable cause) | |
| doFlush | back to summary |
|---|---|
| private void doFlush(final ChannelHandlerContext ctx) | |
| flush | back to summary |
|---|---|
| public void flush(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| handleEndOfInputFuture | back to summary |
|---|---|
| private static void handleEndOfInputFuture(ChannelFuture future, ChunkedInput<?> input, ChunkedWriteHandler. | |
| handleFuture | back to summary |
|---|---|
| private void handleFuture(ChannelFuture future, ChunkedInput<?> input, ChunkedWriteHandler. | |
| handlerAdded | back to summary |
|---|---|
| public void handlerAdded(ChannelHandlerContext ctx) throws Exception Overrides io. Implements io. Doc from io. Gets called after the
| |
| queueIsEmpty | back to summary |
|---|---|
| private boolean queueIsEmpty() | |
| resumeTransfer | back to summary |
|---|---|
| public void resumeTransfer() Continues to fetch the chunks from the input. | |
| resumeTransfer0 | back to summary |
|---|---|
| private void resumeTransfer0(ChannelHandlerContext ctx) | |
| write | back to summary |
|---|---|
| public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception Overrides io. Implements io. Doc from io. Calls
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Object | |
| pack-priv final ChannelPromise |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void | |
| pack-priv void |
| msg | back to summary |
|---|---|
| pack-priv final Object msg | |
| promise | back to summary |
|---|---|
| pack-priv final ChannelPromise promise | |
| PendingWrite | back to summary |
|---|---|
| pack-priv PendingWrite(Object msg, ChannelPromise promise) | |
| fail | back to summary |
|---|---|
| pack-priv void fail(Throwable cause) | |
| progress | back to summary |
|---|---|
| pack-priv void progress(long progress, long total) | |
| success | back to summary |
|---|---|
| pack-priv void success(long total) | |