Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / ReconnectingClientConnection.java
index e15a949600f4f932c96fc83e1d77a5eb296de1c6..e63e7253bcf9b66731e78dc5c698a9d1ab879215 100644 (file)
@@ -7,10 +7,9 @@
  */
 package org.opendaylight.controller.cluster.access.client;
 
-import akka.actor.ActorRef;
-import java.util.Map.Entry;
-import org.opendaylight.controller.cluster.access.concepts.Request;
-import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope;
+import static java.util.Objects.requireNonNull;
+
+import org.opendaylight.controller.cluster.access.concepts.RequestException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -24,25 +23,36 @@ import org.slf4j.LoggerFactory;
 public final class ReconnectingClientConnection<T extends BackendInfo> extends AbstractReceivingClientConnection<T> {
     private static final Logger LOG = LoggerFactory.getLogger(ReconnectingClientConnection.class);
 
-    ReconnectingClientConnection(final ConnectedClientConnection<T> oldConnection) {
+    private RequestException cause;
+
+    ReconnectingClientConnection(final ConnectedClientConnection<T> oldConnection, final RequestException cause) {
         super(oldConnection);
+        this.cause = requireNonNull(cause);
     }
 
     @Override
-    ClientActorBehavior<T> reconnectConnection(final ClientActorBehavior<T> current) {
-        // Intentional no-op
-        LOG.debug("Skipping reconnect of already-reconnecting connection {}", this);
-        return current;
+    long backendSilentTicks(final long now) {
+        // We do not want to reconnect this connection, as we need the timer to to keep running
+        return 0;
     }
 
     @Override
-    Entry<ActorRef, RequestEnvelope> prepareForTransmit(final Request<?, ?> req) {
-        // This is guarded by remoteMaxMessages() == 0
-        throw new UnsupportedOperationException("Attempted to transmit on a reconnecting connection");
+    @SuppressWarnings("checkstyle:hiddenField")
+    ClientActorBehavior<T> lockedReconnect(final ClientActorBehavior<T> current, final RequestException cause) {
+        this.cause = requireNonNull(cause);
+        LOG.warn("Skipping reconnect of already-reconnecting connection {}", this);
+        return current;
     }
 
     @Override
-    int remoteMaxMessages() {
-        return 0;
+    RequestException enrichPoison(final RequestException ex) {
+        if (ex.getCause() != null) {
+            ex.addSuppressed(cause);
+        } else {
+            ex.initCause(cause);
+        }
+
+        return ex;
     }
+
 }