FlushConsolidationHandler remove conditional
Motivation: FlushConsolidationHandler#flushIfNeeded has a conditional which is fixed based upon code path. This conditional can be removed and instead just manually set in each fixed code path. Modifications: - Remove boolean parameter on FlushConsolidationHandler#flushIfNeeded and set readInprogess to false manually when necessary Result: Less conditionals in FlushConsolidationHandler
This commit is contained in:
parent
01523e7835
commit
cebf255951
@ -83,7 +83,7 @@ public class FlushConsolidationHandler extends ChannelDuplexHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||||
// This may be the last event in the read loop, so flush now!
|
// This may be the last event in the read loop, so flush now!
|
||||||
flushIfNeeded(ctx, true);
|
resetReadAndFlushIfNeeded(ctx);
|
||||||
ctx.fireChannelReadComplete();
|
ctx.fireChannelReadComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,21 +96,21 @@ public class FlushConsolidationHandler extends ChannelDuplexHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
// To ensure we not miss to flush anything, do it now.
|
// To ensure we not miss to flush anything, do it now.
|
||||||
flushIfNeeded(ctx, true);
|
resetReadAndFlushIfNeeded(ctx);
|
||||||
ctx.fireExceptionCaught(cause);
|
ctx.fireExceptionCaught(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
|
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
|
||||||
// Try to flush one last time if flushes are pending before disconnect the channel.
|
// Try to flush one last time if flushes are pending before disconnect the channel.
|
||||||
flushIfNeeded(ctx, true);
|
resetReadAndFlushIfNeeded(ctx);
|
||||||
ctx.disconnect(promise);
|
ctx.disconnect(promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
|
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
|
||||||
// Try to flush one last time if flushes are pending before close the channel.
|
// Try to flush one last time if flushes are pending before close the channel.
|
||||||
flushIfNeeded(ctx, true);
|
resetReadAndFlushIfNeeded(ctx);
|
||||||
ctx.close(promise);
|
ctx.close(promise);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,20 +118,22 @@ public class FlushConsolidationHandler extends ChannelDuplexHandler {
|
|||||||
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
||||||
if (!ctx.channel().isWritable()) {
|
if (!ctx.channel().isWritable()) {
|
||||||
// The writability of the channel changed to false, so flush all consolidated flushes now to free up memory.
|
// The writability of the channel changed to false, so flush all consolidated flushes now to free up memory.
|
||||||
flushIfNeeded(ctx, false);
|
flushIfNeeded(ctx);
|
||||||
}
|
}
|
||||||
ctx.fireChannelWritabilityChanged();
|
ctx.fireChannelWritabilityChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
|
||||||
flushIfNeeded(ctx, false);
|
flushIfNeeded(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flushIfNeeded(ChannelHandlerContext ctx, boolean resetReadInProgress) {
|
private void resetReadAndFlushIfNeeded(ChannelHandlerContext ctx) {
|
||||||
if (resetReadInProgress) {
|
readInprogess = false;
|
||||||
readInprogess = false;
|
flushIfNeeded(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void flushIfNeeded(ChannelHandlerContext ctx) {
|
||||||
if (flushPendingCount > 0) {
|
if (flushPendingCount > 0) {
|
||||||
flushPendingCount = 0;
|
flushPendingCount = 0;
|
||||||
ctx.flush();
|
ctx.flush();
|
||||||
|
Loading…
Reference in New Issue
Block a user