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(BufferAllocator), 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 final Queue |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | channelInactive(ChannelHandlerContext ctx)
Overrides default io. Channel of the ChannelHandlerContext was registered is now inactive and reached its
end of lifetime.
|
| public void | channelWritabilityChanged(ChannelHandlerContext ctx)
Overrides default io. Channel changed.
|
| private static void | |
| private void | |
| private void | |
| public void | flush(ChannelHandlerContext
the ctx)ChannelHandlerContext for which the flush operation is madeOverrides default io. |
| private static void | |
| private void | handleFuture(Channel channel, Future<?> future, ChunkedWriteHandler.
|
| public void | handlerAdded(ChannelHandlerContext ctx)
Overrides default io. ChannelHandler was added to the actual context and it's ready to handle events.
|
| public void | |
| private void | |
| public Future | write(ChannelHandlerContext
the ctx, Object ChannelHandlerContext for which the write operation is madethe message to write msg)Overrides default io. |
| ctx | back to summary |
|---|---|
| private volatile ChannelHandlerContext ctx | |
| logger | back to summary |
|---|---|
| private static final InternalLogger logger | |
| queue | back to summary |
|---|---|
| private final Queue<ChunkedWriteHandler. | |
| ChunkedWriteHandler | back to summary |
|---|---|
| public ChunkedWriteHandler() | |
| ChunkedWriteHandler | back to summary |
|---|---|
| public ChunkedWriteHandler(int maxPendingWrites)
Deprecated
| |
| channelInactive | back to summary |
|---|---|
| public void channelInactive(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. The
| |
| channelWritabilityChanged | back to summary |
|---|---|
| public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called once the writable state of a
| |
| 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) Overrides default io. Doc from io. Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.
| |
| handleEndOfInputFuture | back to summary |
|---|---|
| private static void handleEndOfInputFuture(Future<?> future, ChunkedWriteHandler. | |
| handleFuture | back to summary |
|---|---|
| private void handleFuture(Channel channel, Future<?> future, ChunkedWriteHandler. | |
| handlerAdded | back to summary |
|---|---|
| public void handlerAdded(ChannelHandlerContext ctx) throws Exception Overrides default io. Doc from io. Gets called after the
| |
| 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 Future Overrides default io. Doc from io. Called once a write operation is made. The write operation will write the messages through the
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final Object | |
| pack-priv final Promise |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv void |
| msg | back to summary |
|---|---|
| pack-priv final Object msg | |
| promise | back to summary |
|---|---|
| pack-priv final Promise<Void> promise | |
| PendingWrite | back to summary |
|---|---|
| pack-priv PendingWrite(Object msg, Promise<Void> promise) | |
| fail | back to summary |
|---|---|
| pack-priv void fail(Throwable cause) | |
| success | back to summary |
|---|---|
| pack-priv void success() | |