Barrier send condition updated 67/32367/2
authorMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 11 Jan 2016 21:28:52 +0000 (22:28 +0100)
committerMichal Polkorab <michal.polkorab@pantheon.sk>
Mon, 11 Jan 2016 22:21:36 +0000 (23:21 +0100)
 - fixes uncovered case - if a barrier was scheduled and another
   barrier was sent due to exceeded "maxNonBarrierMessages", then we
   would cancel / not enqueue the scheduled barrier because of "sinceLast"
   time - this time is lower than "maxBarrierNanos"

Change-Id: I86f1be2ac0dc76241523ee3b6e6bf12bec90889e
Signed-off-by: Michal Polkorab <michal.polkorab@pantheon.sk>
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/OutboundQueueManager.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/connection/StackedOutboundQueue.java

index 90db23da65d3dfa37b245edf3ce1b6af5d7fd951..1769facefa4f597c487dbfcb479e9ad13e01edaf 100644 (file)
@@ -86,16 +86,11 @@ final class OutboundQueueManager<T extends OutboundQueueHandler> extends
             return;
         }
 
-        final long now = System.nanoTime();
-        final long sinceLast = now - lastBarrierNanos;
-        if (sinceLast >= maxBarrierNanos) {
-            LOG.debug("Last barrier at {} now {}, elapsed {}", lastBarrierNanos, now, sinceLast);
-            // FIXME: we should be tracking requests/responses instead of this
-            if (nonBarrierMessages == 0) {
-                LOG.trace("No messages written since last barrier, not issuing one");
-            } else {
-                scheduleBarrierMessage();
-            }
+        if (currentQueue.isBarrierNeeded()) {
+            LOG.trace("Sending a barrier message");
+            scheduleBarrierMessage();
+        } else {
+            LOG.trace("Barrier not needed, not issuing one");
         }
     }
 
index a9876d99ec9571c634d17254e427cd886780ea95..cafd114c1a021219a5f9af69c103771253e19332 100644 (file)
@@ -51,12 +51,24 @@ final class StackedOutboundQueue extends AbstractStackedOutboundQueue {
     }
 
     Long reserveBarrierIfNeeded() {
+        if (isBarrierNeeded()) {
+            return reserveEntry();
+        }
+        return null;
+    }
+
+    /**
+     * Checks if Barrier Request is the last message enqueued. If not, one needs
+     * to be scheduled in order to collect data about previous messages.
+     * @return true if last enqueued message is Barrier Request, false otherwise
+     */
+    boolean isBarrierNeeded() {
         final long bXid = barrierXid;
         final long fXid = firstSegment.getBaseXid() + flushOffset;
         if (bXid >= fXid) {
             LOG.debug("Barrier found at XID {} (currently at {})", bXid, fXid);
-            return null;
+            return false;
         }
-        return reserveEntry();
+        return true;
     }
 }