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 akka.actor.ActorRef;
11 import com.google.common.annotations.Beta;
12 import javax.annotation.concurrent.NotThreadSafe;
13 import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
19 public final class ConnectedClientConnection<T extends BackendInfo> extends AbstractReceivingClientConnection<T> {
20 private static final Logger LOG = LoggerFactory.getLogger(ConnectedClientConnection.class);
22 private long nextTxSequence;
24 public ConnectedClientConnection(final ClientActorContext context, final Long cookie, final T backend) {
25 super(context, cookie, backend);
28 private TransmittedConnectionEntry transmit(final ConnectionEntry entry) {
29 final long txSequence = nextTxSequence++;
31 final RequestEnvelope toSend = new RequestEnvelope(entry.getRequest().toVersion(remoteVersion()), sessionId(),
34 final ActorRef actor = remoteActor();
35 LOG.trace("Transmitting request {} as {} to {}", entry.getRequest(), toSend, actor);
36 actor.tell(toSend, ActorRef.noSender());
38 return new TransmittedConnectionEntry(entry, sessionId(), txSequence, readTime());
42 void enqueueEntry(final ConnectionEntry entry) {
43 if (inflightSize() < remoteMaxMessages()) {
44 appendToInflight(transmit(entry));
45 LOG.debug("Enqueued request {} to queue {}", entry.getRequest(), this);
47 LOG.debug("Queue is at capacity, delayed sending of request {}", entry.getRequest());
48 super.enqueueEntry(entry);
53 void sendMessages(final int count) {
57 final ConnectionEntry e = dequeEntry();
62 LOG.debug("Transmitting entry {}", e);
63 appendToInflight(transmit(e));
69 ClientActorBehavior<T> reconnectConnection(final ClientActorBehavior<T> current) {
70 final ReconnectingClientConnection<T> next = new ReconnectingClientConnection<>(this);
71 setForwarder(new SimpleReconnectForwarder(next));
72 current.reconnectConnection(this, next);