Skip to content

Commit

Permalink
Do not keep Runnables for the events that are triggered only once in …
Browse files Browse the repository at this point in the history
…most cases
  • Loading branch information
trustin committed Feb 21, 2013
1 parent dfbe4e4 commit 08e2914
Showing 1 changed file with 44 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
ByteBridge.class, "outByteBridge");

// Lazily instantiated tasks used to trigger events to a handler with different executor.
private Runnable invokeChannelRegisteredTask;
private Runnable invokeChannelUnregisteredTask;
private Runnable invokeChannelActiveTask;
private Runnable invokeChannelInactiveTask;
private Runnable invokeInboundBufferUpdatedTask;
private Runnable fireInboundBufferUpdated0Task;
private Runnable invokeChannelReadSuspendedTask;
private Runnable invokeFreeInboundBuffer0Task;
private Runnable invokeFreeOutboundBuffer0Task;
private Runnable invokeRead0Task;
boolean removed;

Expand Down Expand Up @@ -712,16 +706,12 @@ public ChannelHandlerContext fireChannelRegistered() {
if (executor.inEventLoop()) {
next.invokeChannelRegistered();
} else {
Runnable task = next.invokeChannelRegisteredTask;
if (task == null) {
next.invokeChannelRegisteredTask = task = new Runnable() {
@Override
public void run() {
next.invokeChannelRegistered();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
next.invokeChannelRegistered();
}
});
}
return this;
}
Expand All @@ -743,16 +733,12 @@ public ChannelHandlerContext fireChannelUnregistered() {
if (prev != null && executor.inEventLoop()) {
next.invokeChannelUnregistered();
} else {
Runnable task = next.invokeChannelUnregisteredTask;
if (task == null) {
next.invokeChannelUnregisteredTask = task = new Runnable() {
@Override
public void run() {
next.invokeChannelUnregistered();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
next.invokeChannelUnregistered();
}
});
}
return this;
}
Expand All @@ -773,16 +759,12 @@ public ChannelHandlerContext fireChannelActive() {
if (executor.inEventLoop()) {
next.invokeChannelActive();
} else {
Runnable task = next.invokeChannelActiveTask;
if (task == null) {
next.invokeChannelActiveTask = task = new Runnable() {
@Override
public void run() {
next.invokeChannelActive();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
next.invokeChannelActive();
}
});
}
return this;
}
Expand All @@ -804,16 +786,12 @@ public ChannelHandlerContext fireChannelInactive() {
if (prev != null && executor.inEventLoop()) {
next.invokeChannelInactive();
} else {
Runnable task = next.invokeChannelInactiveTask;
if (task == null) {
next.invokeChannelInactiveTask = task = new Runnable() {
@Override
public void run() {
next.invokeChannelInactive();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
next.invokeChannelInactive();
}
});
}
return this;
}
Expand Down Expand Up @@ -1465,17 +1443,13 @@ void invokeFreeInboundBuffer() {
if (prev != null && executor.inEventLoop()) {
invokeFreeInboundBuffer0();
} else {
Runnable task = invokeFreeInboundBuffer0Task;
if (task == null) {
invokeFreeInboundBuffer0Task = task = new Runnable() {
@Override
public void run() {
pipeline.shutdownInbound();
invokeFreeInboundBuffer0();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
pipeline.shutdownInbound();
invokeFreeInboundBuffer0();
}
});
}
}

Expand Down Expand Up @@ -1509,32 +1483,24 @@ private void invokeFreeOutboundBuffer() {
pipeline.shutdownOutbound();
invokeFreeOutboundBuffer0();
} else {
Runnable task = invokeFreeOutboundBuffer0Task;
if (task == null) {
invokeFreeOutboundBuffer0Task = task = new Runnable() {
@Override
public void run() {
pipeline.shutdownOutbound();
invokeFreeOutboundBuffer0();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
pipeline.shutdownOutbound();
invokeFreeOutboundBuffer0();
}
});
}
} else {
if (executor.inEventLoop()) {
invokeFreeOutboundBuffer0();
} else {
Runnable task = invokeFreeOutboundBuffer0Task;
if (task == null) {
invokeFreeOutboundBuffer0Task = task = new Runnable() {
@Override
public void run() {
invokeFreeOutboundBuffer0();
}
};
}
executor.execute(task);
executor.execute(new Runnable() {
@Override
public void run() {
invokeFreeOutboundBuffer0();
}
});
}
}
}
Expand Down

0 comments on commit 08e2914

Please sign in to comment.