Fill/flush bridges only when necessary
This commit is contained in:
parent
87efff0bca
commit
7cefd10d9f
@ -283,7 +283,11 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillBridge() {
|
private void fillInboundBridge() {
|
||||||
|
if (!(handler instanceof ChannelInboundHandler)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (inMsgBridge != null) {
|
if (inMsgBridge != null) {
|
||||||
MessageBridge bridge = inMsgBridge;
|
MessageBridge bridge = inMsgBridge;
|
||||||
if (bridge != null) {
|
if (bridge != null) {
|
||||||
@ -295,6 +299,12 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
bridge.fill();
|
bridge.fill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillOutboundBridge() {
|
||||||
|
if (!(handler instanceof ChannelOutboundHandler)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (outMsgBridge != null) {
|
if (outMsgBridge != null) {
|
||||||
MessageBridge bridge = outMsgBridge;
|
MessageBridge bridge = outMsgBridge;
|
||||||
@ -309,7 +319,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void flushBridge() {
|
private void flushInboundBridge() {
|
||||||
if (inMsgBridge != null) {
|
if (inMsgBridge != null) {
|
||||||
MessageBridge bridge = inMsgBridge;
|
MessageBridge bridge = inMsgBridge;
|
||||||
if (bridge != null) {
|
if (bridge != null) {
|
||||||
@ -321,7 +331,9 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
bridge.flush(inByteBuf);
|
bridge.flush(inByteBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void flushOutboundBridge() {
|
||||||
if (outMsgBridge != null) {
|
if (outMsgBridge != null) {
|
||||||
MessageBridge bridge = outMsgBridge;
|
MessageBridge bridge = outMsgBridge;
|
||||||
if (bridge != null) {
|
if (bridge != null) {
|
||||||
@ -908,7 +920,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
private void fireInboundBufferUpdated0() {
|
private void fireInboundBufferUpdated0() {
|
||||||
final DefaultChannelHandlerContext next = findContextInbound();
|
final DefaultChannelHandlerContext next = findContextInbound();
|
||||||
if (!next.isInboundBufferFreed()) {
|
if (!next.isInboundBufferFreed()) {
|
||||||
next.fillBridge();
|
next.fillInboundBridge();
|
||||||
// This comparison is safe because this method is always executed from the executor.
|
// This comparison is safe because this method is always executed from the executor.
|
||||||
if (next.executor == executor) {
|
if (next.executor == executor) {
|
||||||
next.invokeInboundBufferUpdated();
|
next.invokeInboundBufferUpdated();
|
||||||
@ -931,7 +943,10 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
|
|
||||||
private void invokeInboundBufferUpdated() {
|
private void invokeInboundBufferUpdated() {
|
||||||
ChannelStateHandler handler = (ChannelStateHandler) handler();
|
ChannelStateHandler handler = (ChannelStateHandler) handler();
|
||||||
flushBridge();
|
if (handler instanceof ChannelInboundHandler) {
|
||||||
|
flushInboundBridge();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
handler.inboundBufferUpdated(this);
|
handler.inboundBufferUpdated(this);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@ -1257,7 +1272,7 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
"Unable to flush as outbound buffer of next handler was freed already"));
|
"Unable to flush as outbound buffer of next handler was freed already"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prev.fillBridge();
|
prev.fillOutboundBridge();
|
||||||
prev.invokeFlush(promise, currentThread);
|
prev.invokeFlush(promise, currentThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1285,8 +1300,11 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
ChannelOperationHandler handler = (ChannelOperationHandler) handler();
|
ChannelOperationHandler handler = (ChannelOperationHandler) handler();
|
||||||
|
if (handler instanceof ChannelInboundHandler) {
|
||||||
|
flushOutboundBridge();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
flushBridge();
|
|
||||||
handler.flush(this, promise);
|
handler.flush(this, promise);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
pipeline.notifyHandlerException(t);
|
pipeline.notifyHandlerException(t);
|
||||||
@ -1333,9 +1351,13 @@ final class DefaultChannelHandlerContext extends DefaultAttributeMap implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void invokeSendFile0(FileRegion region, ChannelPromise promise) {
|
private void invokeSendFile0(FileRegion region, ChannelPromise promise) {
|
||||||
|
ChannelOperationHandler handler = (ChannelOperationHandler) handler();
|
||||||
|
if (handler instanceof ChannelOutboundHandler) {
|
||||||
|
flushOutboundBridge();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
flushBridge();
|
handler.sendFile(this, region, promise);
|
||||||
((ChannelOperationHandler) handler()).sendFile(this, region, promise);
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
pipeline.notifyHandlerException(t);
|
pipeline.notifyHandlerException(t);
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user