Bug 4942 - Barrier send condition updated
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / connection / StackedOutboundQueue.java
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;
     }
 }