Simplified Chunked resource management
This commit is contained in:
parent
347131e0fa
commit
925a99a572
@ -139,12 +139,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
|||||||
|
|
||||||
Object m = currentEvent.getMessage();
|
Object m = currentEvent.getMessage();
|
||||||
if (m instanceof ChunkedInput) {
|
if (m instanceof ChunkedInput) {
|
||||||
ChunkedInput chunks = (ChunkedInput) m;
|
closeInput((ChunkedInput) m);
|
||||||
try {
|
|
||||||
chunks.close();
|
|
||||||
} catch (Throwable t2) {
|
|
||||||
logger.warn("Failed to close a chunked input.", t2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger a ClosedChannelException
|
// Trigger a ClosedChannelException
|
||||||
Channels.write(
|
Channels.write(
|
||||||
@ -194,11 +189,7 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
fireExceptionCaught(ctx, t);
|
fireExceptionCaught(ctx, t);
|
||||||
|
|
||||||
try {
|
closeInput(chunks);
|
||||||
chunks.close();
|
|
||||||
} catch (Throwable t2) {
|
|
||||||
logger.warn("Failed to close a chunked input.", t2);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,14 +197,8 @@ public class ChunkedWriteHandler implements ChannelUpstreamHandler, ChannelDowns
|
|||||||
final MessageEvent currentEvent = this.currentEvent;
|
final MessageEvent currentEvent = this.currentEvent;
|
||||||
if (last) {
|
if (last) {
|
||||||
this.currentEvent = null;
|
this.currentEvent = null;
|
||||||
|
closeInput(chunks);
|
||||||
writeFuture = currentEvent.getFuture();
|
writeFuture = currentEvent.getFuture();
|
||||||
writeFuture.addListener(new ChannelFutureListener() {
|
|
||||||
public void operationComplete(ChannelFuture future)
|
|
||||||
throws Exception {
|
|
||||||
((ChunkedInput) currentEvent.getMessage()).close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
writeFuture = future(channel);
|
writeFuture = future(channel);
|
||||||
writeFuture.addListener(new ChannelFutureListener() {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user