Package org.jboss.netty.handler.stream
Class ChunkedWriteHandler
- java.lang.Object
-
- org.jboss.netty.handler.stream.ChunkedWriteHandler
-
- All Implemented Interfaces:
ChannelDownstreamHandler,ChannelHandler,ChannelUpstreamHandler,LifeCycleAwareChannelHandler
public class ChunkedWriteHandler extends Object implements ChannelUpstreamHandler, ChannelDownstreamHandler, LifeCycleAwareChannelHandler
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.nextChunk(), resulting in the indefinitely suspended transfer. To resume the transfer when a new chunk is available, you have to callresumeTransfer().
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Constructor Summary
Constructors Constructor Description ChunkedWriteHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAdd(ChannelHandlerContext ctx)voidafterRemove(ChannelHandlerContext ctx)voidbeforeAdd(ChannelHandlerContext ctx)voidbeforeRemove(ChannelHandlerContext ctx)voidhandleDownstream(ChannelHandlerContext ctx, ChannelEvent e)Handles the specified downstream event.voidhandleUpstream(ChannelHandlerContext ctx, ChannelEvent e)Handles the specified upstream event.voidresumeTransfer()Continues to fetch the chunks from the input.
-
-
-
Method Detail
-
resumeTransfer
public void resumeTransfer()
Continues to fetch the chunks from the input.
-
handleDownstream
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
Description copied from interface:ChannelDownstreamHandlerHandles the specified downstream event.- Specified by:
handleDownstreamin interfaceChannelDownstreamHandler- Parameters:
ctx- the context object for this handlere- the downstream event to process or intercept- Throws:
Exception
-
handleUpstream
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception
Description copied from interface:ChannelUpstreamHandlerHandles the specified upstream event.- Specified by:
handleUpstreamin interfaceChannelUpstreamHandler- Parameters:
ctx- the context object for this handlere- the upstream event to process or intercept- Throws:
Exception
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
Exception
-
-