2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.access.client;
10 import com.google.common.base.MoreObjects.ToStringHelper;
11 import com.google.common.base.Preconditions;
12 import java.util.Optional;
15 * Implementation-internal intermediate subclass between {@link AbstractClientConnection} and two-out of three of its
16 * subclasses. It allows us to share some code.
18 * @author Robert Varga
20 * @param <T> Concrete {@link BackendInfo} type
22 abstract class AbstractReceivingClientConnection<T extends BackendInfo> extends AbstractClientConnection<T> {
24 * Multiplication factor applied to remote's advertised limit on outstanding messages. Our default strategy
25 * rate-limiting strategy in {@link AveragingProgressTracker} does not penalize threads as long as we have not
26 * reached half of the target.
29 * By multiplying the advertised maximum by four, our queue steady-state should end up with:
30 * - the backend pipeline being full,
31 * - another full batch of messages being in the queue while not paying any throttling cost
32 * - another 2 full batches of messages with incremental throttling cost
34 private static final int MESSAGE_QUEUE_FACTOR = 4;
36 private final T backend;
38 AbstractReceivingClientConnection(final ClientActorContext context, final Long cookie, final T backend) {
39 super(context, cookie, new TransmitQueue.Transmitting(targetQueueSize(backend), backend));
40 this.backend = Preconditions.checkNotNull(backend);
43 AbstractReceivingClientConnection(final AbstractReceivingClientConnection<T> oldConnection) {
44 super(oldConnection, targetQueueSize(oldConnection.backend));
45 this.backend = oldConnection.backend;
48 private static int targetQueueSize(final BackendInfo backend) {
49 return backend.getMaxMessages() * MESSAGE_QUEUE_FACTOR;
53 public final Optional<T> getBackendInfo() {
54 return Optional.of(backend);
62 ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
63 return super.addToStringAttributes(toStringHelper).add("backend", backend);