Fix sonar warnings in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / AbstractDataStoreClientBehavior.java
index 007f3875cf146ceb6863eb0f3888fd3935ef46fc..77db4e6c0804073392950c122d3f0cfa8911daee 100644 (file)
@@ -21,6 +21,8 @@ import org.opendaylight.controller.cluster.access.client.BackendInfoResolver;
 import org.opendaylight.controller.cluster.access.client.ClientActorBehavior;
 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
 import org.opendaylight.controller.cluster.access.client.ConnectedClientConnection;
+import org.opendaylight.controller.cluster.access.client.ConnectionEntry;
+import org.opendaylight.controller.cluster.access.client.ReconnectForwarder;
 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.slf4j.Logger;
@@ -139,29 +141,33 @@ abstract class AbstractDataStoreClientBehavior extends ClientActorBehavior<Shard
             startReconnect(h, newConn, cohorts);
         }
 
-        return previousEntries -> {
+        return previousEntries -> finishReconnect(newConn, stamp, cohorts, previousEntries);
+    }
+
+    private ReconnectForwarder finishReconnect(final ConnectedClientConnection<ShardBackendInfo> newConn,
+            final long stamp, final Collection<HistoryReconnectCohort> cohorts,
+            final Collection<ConnectionEntry> previousEntries) {
+        try {
+            // Step 2: Collect previous successful requests from the cohorts. We do not want to expose
+            //         the non-throttling interface to the connection, hence we use a wrapper consumer
+            for (HistoryReconnectCohort c : cohorts) {
+                c.replayRequests(previousEntries);
+            }
+
+            // Step 3: Install a forwarder, which will forward requests back to affected cohorts. Any outstanding
+            //         requests will be immediately sent to it and requests being sent concurrently will get
+            //         forwarded once they hit the new connection.
+            return BouncingReconnectForwarder.forCohorts(newConn, cohorts);
+        } finally {
             try {
-                // Step 2: Collect previous successful requests from the cohorts. We do not want to expose
-                //         the non-throttling interface to the connection, hence we use a wrapper consumer
+                // Step 4: Complete switchover of the connection. The cohorts can resume normal operations.
                 for (HistoryReconnectCohort c : cohorts) {
-                    c.replayRequests(previousEntries);
+                    c.close();
                 }
-
-                // Step 3: Install a forwarder, which will forward requests back to affected cohorts. Any outstanding
-                //         requests will be immediately sent to it and requests being sent concurrently will get
-                //         forwarded once they hit the new connection.
-                return BouncingReconnectForwarder.forCohorts(newConn, cohorts);
             } finally {
-                try {
-                    // Step 4: Complete switchover of the connection. The cohorts can resume normal operations.
-                    for (HistoryReconnectCohort c : cohorts) {
-                        c.close();
-                    }
-                } finally {
-                    lock.unlockWrite(stamp);
-                }
+                lock.unlockWrite(stamp);
             }
-        };
+        }
     }
 
     private static void startReconnect(final AbstractClientHistory history,