X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fclient%2FAbstractReceivingClientConnection.java;h=b369aea9dd736e6b9716207a6c4abe179e1ae6ad;hb=refs%2Fchanges%2F05%2F83005%2F5;hp=15da294ec99fbcd4ed49417500d55b8dae950432;hpb=b4d95acff78952020e9fbde4372d13b461fd7469;p=controller.git diff --git a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractReceivingClientConnection.java b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractReceivingClientConnection.java index 15da294ec9..b369aea9dd 100644 --- a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractReceivingClientConnection.java +++ b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractReceivingClientConnection.java @@ -7,36 +7,74 @@ */ 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 - * sublcasses. It allows us to share some code. + * subclasses. It allows us to share some code. * * @author Robert Varga * * @param Concrete {@link BackendInfo} type */ abstract class AbstractReceivingClientConnection extends AbstractClientConnection { + 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 + * reached half of the target. + * + *

+ * 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; - AbstractReceivingClientConnection(final ClientActorContext context, final Long cookie, final T backend) { - super(context, cookie, new TransmitQueue.Transmitting(backend)); - this.backend = Preconditions.checkNotNull(backend); + // To be called by ConnectedClientConnection only. + AbstractReceivingClientConnection(final AbstractClientConnection oldConnection, final T newBackend) { + super(oldConnection, newBackend, targetQueueSize(newBackend)); + this.backend = newBackend; } + // To be called by ReconnectingClientConnection only. AbstractReceivingClientConnection(final AbstractReceivingClientConnection oldConnection) { super(oldConnection); this.backend = oldConnection.backend; } + private static int targetQueueSize(final BackendInfo backend) { + return backend.getMaxMessages() * MESSAGE_QUEUE_FACTOR; + } + @Override public final Optional getBackendInfo() { 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); + } }