Not wakeup the EventLoop for writes as they will not cause a flush anyway

This commit is contained in:
Norman Maurer 2014-01-30 20:02:15 +01:00
parent f7f808c7e0
commit 1d8a200849
3 changed files with 20 additions and 5 deletions

View File

@ -658,11 +658,16 @@ public abstract class SingleThreadEventExecutor extends AbstractEventExecutor {
} }
} }
if (!addTaskWakesUp) { if (!addTaskWakesUp && wakesUpForTask(task)) {
wakeup(inEventLoop); wakeup(inEventLoop);
} }
} }
@SuppressWarnings("unused")
protected boolean wakesUpForTask(Runnable task) {
return true;
}
protected static void reject() { protected static void reject() {
throw new RejectedExecutionException("event executor terminated"); throw new RejectedExecutionException("event executor terminated");
} }

View File

@ -383,7 +383,7 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
} }
} }
static final class WriteTask implements Runnable { static final class WriteTask implements SingleThreadEventLoop.NonWakeupRunnable {
private ChannelHandlerContext ctx; private ChannelHandlerContext ctx;
private Object msg; private Object msg;
private ChannelPromise promise; private ChannelPromise promise;
@ -391,7 +391,7 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
private static final Recycler<WriteTask> RECYCLER = new Recycler<WriteTask>() { private static final Recycler<WriteTask> RECYCLER = new Recycler<WriteTask>() {
@Override @Override
protected WriteTask newObject(Handle handle) { protected WriteTask newObject(Handle<WriteTask> handle) {
return new WriteTask(handle); return new WriteTask(handle);
} }
}; };
@ -406,9 +406,9 @@ public class DefaultChannelHandlerInvoker implements ChannelHandlerInvoker {
return task; return task;
} }
private final Recycler.Handle handle; private final Recycler.Handle<WriteTask> handle;
private WriteTask(Recycler.Handle handle) { private WriteTask(Recycler.Handle<WriteTask> handle) {
this.handle = handle; this.handle = handle;
} }

View File

@ -50,4 +50,14 @@ public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor im
public ChannelHandlerInvoker asInvoker() { public ChannelHandlerInvoker asInvoker() {
return invoker; return invoker;
} }
@Override
protected boolean wakesUpForTask(Runnable task) {
return !(task instanceof NonWakeupRunnable);
}
/**
* Marker interface for {@linkRunnable} that will not trigger an {@link #wakeup(boolean)} in all cases.
*/
interface NonWakeupRunnable extends Runnable { }
} }