Bug 5280: Add ProgressTracker
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / AbstractReceivingClientConnection.java
index 8646bfcba5bcb14aac89ac63df6eaa4abbd61e9e..8d9ed24043f41758ef461dc29fb74aefe0008373 100644 (file)
@@ -12,25 +12,40 @@ import java.util.Optional;
 
 /**
  * Implementation-internal intermediate subclass between {@link AbstractClientConnection} and two-out of three of its
- * sublcasses. It allows us to share some code.
+ * subclasses. It allows us to share some code.
  *
  * @author Robert Varga
  *
  * @param <T> Concrete {@link BackendInfo} type
  */
 abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends AbstractClientConnection<T> {
+    /**
+     * Multiplication factor applied to remote's advertised limit on outstanding messages. Our default strategy
+     * rate-limiting strategy in {@link AveragingProgressTracker} does not penalize threads as long as we have not
+     * reached half of the target.
+     *
+     * <p>
+     * By multiplying the advertised maximum by four, our queue steady-state should end up with:
+     * - the backend pipeline being full,
+     * - another full batch of messages being in the queue while not paying any throttling cost
+     * - another 2 full batches of messages with incremental throttling cost
+     */
+    private static final int MESSAGE_QUEUE_FACTOR = 4;
+
     private final T backend;
-    private long nextTxSequence;
 
     AbstractReceivingClientConnection(final ClientActorContext context, final Long cookie, final T backend) {
-        super(context, cookie);
+        super(context, cookie, new TransmitQueue.Transmitting(targetQueueSize(backend), backend));
         this.backend = Preconditions.checkNotNull(backend);
     }
 
     AbstractReceivingClientConnection(final AbstractReceivingClientConnection<T> oldConnection) {
-        super(oldConnection);
+        super(oldConnection, targetQueueSize(oldConnection.backend));
         this.backend = oldConnection.backend;
-        this.nextTxSequence = oldConnection.nextTxSequence;
+    }
+
+    private static int targetQueueSize(final BackendInfo backend) {
+        return backend.getMaxMessages() * MESSAGE_QUEUE_FACTOR;
     }
 
     @Override
@@ -41,8 +56,4 @@ abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends
     final T backend() {
         return backend;
     }
-
-    final long nextTxSequence() {
-        return nextTxSequence++;
-    }
 }