Free the cleared buffer as early as possible / Better naming

This commit is contained in:
Trustin Lee 2013-05-16 19:41:02 +09:00
parent dc13b68632
commit 2040b07849
2 changed files with 34 additions and 34 deletions

View File

@ -198,12 +198,12 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
outMsgBuf = null;
}
void forwardBufferContentAndRemove(
void forwardBufferContentAndFree(
final DefaultChannelHandlerContext forwardPrev, final DefaultChannelHandlerContext forwardNext) {
boolean flush = false;
boolean inboundBufferUpdated = false;
try {
boolean flush = false;
boolean inboundBufferUpdated = false;
if (!isOutboundFreed()) {
if (hasOutboundByteBuffer() && outboundByteBuffer().isReadable()) {
ByteBuf forwardPrevBuf;
@ -251,40 +251,40 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
}
}
}
if (flush) {
EventExecutor executor = executor();
Thread currentThread = Thread.currentThread();
if (executor.inEventLoop(currentThread)) {
invokePrevFlush(newPromise(), currentThread, findContextOutboundInclusive(forwardPrev));
} else {
executor.execute(new Runnable() {
@Override
public void run() {
invokePrevFlush(newPromise(), Thread.currentThread(),
findContextOutboundInclusive(forwardPrev));
}
});
}
}
if (inboundBufferUpdated) {
EventExecutor executor = executor();
if (executor.inEventLoop()) {
fireInboundBufferUpdated0(findContextInboundInclusive(forwardNext));
} else {
executor.execute(new Runnable() {
@Override
public void run() {
fireInboundBufferUpdated0(findContextInboundInclusive(forwardNext));
}
});
}
}
} finally {
flags |= FLAG_REMOVED;
freeAllIfRemoved();
}
if (flush) {
EventExecutor executor = executor();
Thread currentThread = Thread.currentThread();
if (executor.inEventLoop(currentThread)) {
invokePrevFlush(newPromise(), currentThread, findContextOutboundInclusive(forwardPrev));
} else {
executor.execute(new Runnable() {
@Override
public void run() {
invokePrevFlush(newPromise(), Thread.currentThread(),
findContextOutboundInclusive(forwardPrev));
}
});
}
}
if (inboundBufferUpdated) {
EventExecutor executor = executor();
if (executor.inEventLoop()) {
fireInboundBufferUpdated0(findContextInboundInclusive(forwardNext));
} else {
executor.execute(new Runnable() {
@Override
public void run() {
fireInboundBufferUpdated0(findContextInboundInclusive(forwardNext));
}
});
}
}
}
private static DefaultChannelHandlerContext findContextOutboundInclusive(DefaultChannelHandlerContext ctx) {

View File

@ -541,7 +541,7 @@ final class DefaultChannelPipeline implements ChannelPipeline {
// Finish removal by forwarding buffer content and freeing the buffers.
if (forward) {
try {
ctx.forwardBufferContentAndRemove(ctxPrev, ctxNext);
ctx.forwardBufferContentAndFree(ctxPrev, ctxNext);
} catch (Throwable t) {
fireExceptionCaught(new ChannelPipelineException(
"failed to forward buffer content of " + ctx.handler().getClass().getName(), t));