public class ChunkedWriteHandler extends ChannelDuplexHandler
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().ChannelHandler.Sharable| 构造器和说明 |
|---|
ChunkedWriteHandler() |
ChunkedWriteHandler(int maxPendingWrites)
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
channelInactive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
void |
channelWritabilityChanged(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelWritabilityChanged() to forward
to the next ChannelInboundHandler in the ChannelPipeline. |
void |
flush(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.flush() to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
resumeTransfer()
Continues to fetch the chunks from the input.
|
void |
write(ChannelHandlerContext ctx,
java.lang.Object msg,
ChannelPromise promise)
Calls
ChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline. |
bind, close, connect, deregister, disconnect, readchannelActive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, exceptionCaught, userEventTriggeredensureNotSharable, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaught, handlerRemovedpublic ChunkedWriteHandler()
@Deprecated public ChunkedWriteHandler(int maxPendingWrites)
ChunkedWriteHandler()public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapterhandlerAdded 在接口中 ChannelHandlerhandlerAdded 在类中 ChannelHandlerAdapterjava.lang.Exceptionpublic void resumeTransfer()
public void write(ChannelHandlerContext ctx, java.lang.Object msg, ChannelPromise promise) throws java.lang.Exception
ChannelDuplexHandlerChannelOutboundInvoker.write(Object, ChannelPromise) to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.write 在接口中 ChannelOutboundHandlerwrite 在类中 ChannelDuplexHandlerctx - the ChannelHandlerContext for which the write operation is mademsg - the message to writepromise - the ChannelPromise to notify once the operation completesjava.lang.Exception - thrown if an error occurspublic void flush(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelDuplexHandlerChannelHandlerContext.flush() to forward
to the next ChannelOutboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.flush 在接口中 ChannelOutboundHandlerflush 在类中 ChannelDuplexHandlerctx - the ChannelHandlerContext for which the flush operation is madejava.lang.Exception - thrown if an error occurspublic void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelInactive 在接口中 ChannelInboundHandlerchannelInactive 在类中 ChannelInboundHandlerAdapterjava.lang.Exceptionpublic void channelWritabilityChanged(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapterChannelHandlerContext.fireChannelWritabilityChanged() to forward
to the next ChannelInboundHandler in the ChannelPipeline.
Sub-classes may override this method to change behavior.channelWritabilityChanged 在接口中 ChannelInboundHandlerchannelWritabilityChanged 在类中 ChannelInboundHandlerAdapterjava.lang.Exception