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:
parent
9d675def81
commit
ad7f033c06
@ -256,15 +256,20 @@ public class IdleStateHandler extends ChannelDuplexHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||||
ChannelPromise unvoid = promise.unvoid();
|
// Allow writing with void promise if handler is only configured for read timeout events.
|
||||||
unvoid.addListener(new ChannelFutureListener() {
|
if (writerIdleTimeNanos > 0 || allIdleTimeNanos > 0) {
|
||||||
@Override
|
ChannelPromise unvoid = promise.unvoid();
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
unvoid.addListener(new ChannelFutureListener() {
|
||||||
lastWriteTime = System.nanoTime();
|
@Override
|
||||||
firstWriterIdleEvent = firstAllIdleEvent = true;
|
public void operationComplete(ChannelFuture future) throws Exception {
|
||||||
}
|
lastWriteTime = System.nanoTime();
|
||||||
});
|
firstWriterIdleEvent = firstAllIdleEvent = true;
|
||||||
ctx.write(msg, unvoid);
|
}
|
||||||
|
});
|
||||||
|
ctx.write(msg, unvoid);
|
||||||
|
} else {
|
||||||
|
ctx.write(msg, promise);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize(ChannelHandlerContext ctx) {
|
private void initialize(ChannelHandlerContext ctx) {
|
||||||
|
Loading…
Reference in New Issue
Block a user