org.jboss.netty.handler.stream
Class ChunkedWriteHandler

java.lang.Object
  extended by org.jboss.netty.handler.stream.ChunkedWriteHandler
All Implemented Interfaces:
ChannelDownstreamHandler, ChannelHandler, ChannelUpstreamHandler

public class ChunkedWriteHandler
extends Object
implements ChannelUpstreamHandler, ChannelDownstreamHandler

A 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:

 ChannelPipeline p = ...;
 p.addLast("streamer", new ChunkedWriteHandler());
 p.addLast("handler", new MyHandler());
 
Once inserted, you can write a 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:
 Channel ch = ...;
 ch.write(new ChunkedFile(new File("video.mkv"));
 

Sending a stream which generates a chunk intermittently

Some ChunkedInput generates a chunk on a certain event or timing. Such ChunkedInput implementation often returns null on ChunkedInput.nextChunk(), resulting in the indefinitely suspended transfer. To resume the transfer when a new chunk is available, you have to call resumeTransfer().

Version:
$Rev: 2233 $, $Date: 2010-04-06 17:43:49 +0900 (Tue, 06 Apr 2010) $
Author:
The Netty Project, Trustin Lee

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
 
Constructor Summary
ChunkedWriteHandler()
          Creates a new instance.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChunkedWriteHandler

public ChunkedWriteHandler()
Creates a new instance.

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 interface ChannelDownstreamHandler
Parameters:
ctx - the context object for this handler
e - 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 interface ChannelUpstreamHandler
Parameters:
ctx - the context object for this handler
e - the upstream event to process or intercept
Throws:
Exception


Copyright © 2008-2011 JBoss, a division of Red Hat, Inc.. All Rights Reserved.