Bug 8619: Introduce inheritance of progress trackers
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / AbstractReceivingClientConnection.java
index 8d9ed24043f41758ef461dc29fb74aefe0008373..b369aea9dd736e6b9716207a6c4abe179e1ae6ad 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.controller.cluster.access.client;
 
-import com.google.common.base.Preconditions;
+import com.google.common.base.MoreObjects.ToStringHelper;
 import java.util.Optional;
+import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Implementation-internal intermediate subclass between {@link AbstractClientConnection} and two-out of three of its
@@ -19,6 +22,8 @@ import java.util.Optional;
  * @param <T> Concrete {@link BackendInfo} type
  */
 abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends AbstractClientConnection<T> {
+    private static final Logger LOG = LoggerFactory.getLogger(AbstractReceivingClientConnection.class);
+
     /**
      * 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
@@ -34,13 +39,15 @@ abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends
 
     private final T backend;
 
-    AbstractReceivingClientConnection(final ClientActorContext context, final Long cookie, final T backend) {
-        super(context, cookie, new TransmitQueue.Transmitting(targetQueueSize(backend), backend));
-        this.backend = Preconditions.checkNotNull(backend);
+    // To be called by ConnectedClientConnection only.
+    AbstractReceivingClientConnection(final AbstractClientConnection<T> oldConnection, final T newBackend) {
+        super(oldConnection, newBackend, targetQueueSize(newBackend));
+        this.backend = newBackend;
     }
 
+    // To be called by ReconnectingClientConnection only.
     AbstractReceivingClientConnection(final AbstractReceivingClientConnection<T> oldConnection) {
-        super(oldConnection, targetQueueSize(oldConnection.backend));
+        super(oldConnection);
         this.backend = oldConnection.backend;
     }
 
@@ -53,7 +60,21 @@ abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends
         return Optional.of(backend);
     }
 
+    @Override
+    final void receiveResponse(final ResponseEnvelope<?> envelope) {
+        if (envelope.getSessionId() != backend.getSessionId()) {
+            LOG.debug("Response {} does not match session ID {}, ignoring it", envelope, backend.getSessionId());
+        } else {
+            super.receiveResponse(envelope);
+        }
+    }
+
     final T backend() {
         return backend;
     }
+
+    @Override
+    ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+        return super.addToStringAttributes(toStringHelper).add("backend", backend);
+    }
 }