From cefbc1e206effcc6d7dc39d860ab2829d3c3cf2a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 1 Jun 2015 22:52:14 +0200 Subject: [PATCH] Run flush immediately when channel becomes writable Instead of scheduling it on the executor, make sure we run the flush task immediately. Change-Id: Ic0cf9d031127d8e744a5cd79cfe440d52b3c3f0b Signed-off-by: Robert Varga --- .../core/connection/OutboundQueueImpl.java | 1 + .../core/connection/OutboundQueueManager.java | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java index 5698eeec..c4feb26a 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueImpl.java @@ -107,6 +107,7 @@ final class OutboundQueueImpl implements OutboundQueue { } // We have traveled back, recover + LOG.debug("Queue {} retry pending barrier {} >= {}", this, prev, my); my = prev; } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java index 948424f9..b3b7b8c3 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java @@ -334,7 +334,7 @@ final class OutboundQueueManager extends Channel long messages = 0; for (;; ++messages) { if (!parent.getChannel().isWritable()) { - LOG.trace("Channel is no longer writable"); + LOG.debug("Channel {} is no longer writable", parent.getChannel()); break; } @@ -383,8 +383,12 @@ final class OutboundQueueManager extends Channel * to be writable. May only be called from Netty context. */ private void conditionalFlush() { - if (currentQueue.needsFlush() && (shutdownOffset != null || parent.getChannel().isWritable())) { - scheduleFlush(); + if (currentQueue.needsFlush()) { + if (shutdownOffset != null || parent.getChannel().isWritable()) { + scheduleFlush(); + } else { + LOG.debug("Channel {} is not I/O ready, not scheduling a flush", parent.getChannel()); + } } else { LOG.trace("Queue is empty, no flush needed"); } @@ -404,7 +408,13 @@ final class OutboundQueueManager extends Channel @Override public void channelWritabilityChanged(final ChannelHandlerContext ctx) throws Exception { super.channelWritabilityChanged(ctx); - conditionalFlush(ctx); + + if (flushScheduled.compareAndSet(false, true)) { + LOG.debug("Channel {} writability changed, invoking flush", parent.getChannel()); + flush(); + } else { + LOG.debug("Channel {} Writability changed, but task is already scheduled", parent.getChannel()); + } } @Override -- 2.36.6