Simplified Chunked resource management

This commit is contained in:
Trustin Lee 2009-08-27 06:14:28 +00:00
parent 347131e0fa
commit 925a99a572

View File

@ -139,12 +139,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
Object m = currentEvent.getMessage();
if (m instanceof ChunkedInput) {
ChunkedInput chunks = (ChunkedInput) m;
try {
chunks.close();
} catch (Throwable t2) {
logger.warn("Failed to close a chunked input.", t2);
}
closeInput((ChunkedInput) m);
// Trigger a ClosedChannelException
Channels.write(
@ -194,11 +189,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
t.printStackTrace();
fireExceptionCaught(ctx, t);
try {
chunks.close();
} catch (Throwable t2) {
logger.warn("Failed to close a chunked input.", t2);
}
closeInput(chunks);
break;
}
@ -206,14 +197,8 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
final MessageEvent currentEvent = this.currentEvent;
if (last) {
this.currentEvent = null;
closeInput(chunks);
writeFuture = currentEvent.getFuture();
writeFuture.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future)
throws Exception {
((ChunkedInput) currentEvent.getMessage()).close();
}
});
} else {
writeFuture = future(channel);
writeFuture.addListener(new ChannelFutureListener() {
@ -240,4 +225,12 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
}
}
}
private void closeInput(ChunkedInput chunks) {
try {
chunks.close();
} catch (Throwable t2) {
logger.warn("Failed to close a chunked input.", t2);
}
}
}