Allow writing with void promise if IdleStateHandler is configured in pipeline.

Motivation:

Allow writing with void promise if IdleStateHandler is configured in the pipeline for read timeout events.

Modifications:

Better performance.

Result:

No more ChannelFutureListeners are created if IdleStateHandler is only configured for read timeouts allowing for writing to the channel with void promise.
This commit is contained in:
johnou 2015-05-25 19:16:18 +02:00 committed by Norman Maurer
parent 9d675def81
commit ad7f033c06

View File

@ -256,6 +256,8 @@ public class IdleStateHandler extends ChannelDuplexHandler {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
// Allow writing with void promise if handler is only configured for read timeout events.
if (writerIdleTimeNanos > 0 || allIdleTimeNanos > 0) {
ChannelPromise unvoid = promise.unvoid();
unvoid.addListener(new ChannelFutureListener() {
@Override
@ -265,6 +267,9 @@ public class IdleStateHandler extends ChannelDuplexHandler {
}
});
ctx.write(msg, unvoid);
} else {
ctx.write(msg, promise);
}
}
private void initialize(ChannelHandlerContext ctx) {