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
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.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 void
afterAdd(ChannelHandlerContext ctx)
void
afterRemove(ChannelHandlerContext ctx)
void
beforeAdd(ChannelHandlerContext ctx)
void
beforeRemove(ChannelHandlerContext ctx)
void
handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
Handles the specified downstream event.void
handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
Handles the specified upstream event.void
resumeTransfer()
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:ChannelDownstreamHandler
Handles the specified downstream event.- Specified by:
handleDownstream
in 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:ChannelUpstreamHandler
Handles the specified upstream event.- Specified by:
handleUpstream
in 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:
beforeAdd
in interfaceLifeCycleAwareChannelHandler
- Throws:
Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterAdd
in interfaceLifeCycleAwareChannelHandler
- Throws:
Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
beforeRemove
in interfaceLifeCycleAwareChannelHandler
- Throws:
Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws Exception
- Specified by:
afterRemove
in interfaceLifeCycleAwareChannelHandler
- Throws:
Exception
-
-