From e7c329cc4edb6f09923dd86e828d7b3c84702d3f Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 18 Feb 2010 11:33:54 +0000 Subject: [PATCH] Documentation --- .../handler/stream/ChunkedWriteHandler.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java b/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java index c9c69d3dee..44ac3c51b5 100644 --- a/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java +++ b/src/main/java/org/jboss/netty/handler/stream/ChunkedWriteHandler.java @@ -59,6 +59,14 @@ import org.jboss.netty.util.internal.LinkedTransferQueue; * ch.write(new {@link ChunkedFile}(new File("video.mkv")); * * + *

Sending a stream which generates a chunk intermittently

+ * + * Some {@link ChunkedInput} generates a chunk on a certain event or timing. + * Such {@link ChunkedInput} implementation often returns {@code false} on + * {@link ChunkedInput#hasNextChunk()}, resulting in the indefinitely suspended + * transfer. To resume the transfer when a new chunk is available, you have to + * call {@link #resumeTransfer()}. + * * @author The Netty Project * @author Trustin Lee * @version $Rev$, $Date$ @@ -74,6 +82,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns private final Queue queue = new LinkedTransferQueue(); + private ChannelHandlerContext ctx; private MessageEvent currentEvent; /** @@ -83,6 +92,22 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns super(); } + /** + * Continues to fetch the chunks from the input. + */ + public void resumeTransfer() { + ChannelHandlerContext ctx = this.ctx; + if (ctx == null) { + return; + } + + try { + flush(ctx); + } catch (Exception e) { + logger.warn("Unexpected exception while sending chunks.", e); + } + } + public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { if (!(e instanceof MessageEvent)) { @@ -94,6 +119,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns assert offered; if (ctx.getChannel().isWritable()) { + this.ctx = ctx; flush(ctx); } }