Split up RecoveringClientActorBehavior.onReceiveRecover() 84/111684/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 10 May 2024 15:18:44 +0000 (17:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 14 May 2024 08:24:56 +0000 (10:24 +0200)
We will be expanding logic here, split the methods up so it is clearer
what is going on.

JIRA: CONTROLLER-2116
Change-Id: I6dbfb6fb6106c2e342e448b714b708c1e4e65d04
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/RecoveringClientActorBehavior.java

index e97df6af2e91aafba9c26150caa96bc7d976c13a..729d53dfc36445debce67c52174ea3729eee7ed0 100644 (file)
@@ -46,31 +46,38 @@ final class RecoveringClientActorBehavior extends AbstractClientActorBehavior<In
 
     @Override
     AbstractClientActorBehavior<?> onReceiveRecover(final Object recover) {
-        if (recover instanceof RecoveryCompleted) {
-            final ClientIdentifier nextId;
-            if (lastId != null) {
-                if (!currentFrontend.equals(lastId.getFrontendId())) {
-                    LOG.error("{}: Mismatched frontend identifier, shutting down. Current: {} Saved: {}",
-                        persistenceId(), currentFrontend, lastId.getFrontendId());
-                    return null;
-                }
+        if (recover instanceof RecoveryCompleted msg) {
+            return onRecoveryCompleted(msg);
+        } else if (recover instanceof SnapshotOffer snapshotOffer) {
+            onSnapshotOffer(snapshotOffer);
+        } else {
+            LOG.warn("{}: ignoring recovery message {}", persistenceId(), recover);
+        }
+        return this;
+    }
 
-                nextId = ClientIdentifier.create(currentFrontend, lastId.getGeneration() + 1);
-            } else {
-                nextId = ClientIdentifier.create(currentFrontend, initialGeneration());
+    private void onSnapshotOffer(final SnapshotOffer snapshotOffer) {
+        lastId = (ClientIdentifier) snapshotOffer.snapshot();
+        LOG.debug("{}: recovered identifier {}", persistenceId(), lastId);
+    }
+
+    private SavingClientActorBehavior onRecoveryCompleted(final RecoveryCompleted msg) {
+        final ClientIdentifier nextId;
+        if (lastId != null) {
+            if (!currentFrontend.equals(lastId.getFrontendId())) {
+                LOG.error("{}: Mismatched frontend identifier, shutting down. Current: {} Saved: {}",
+                    persistenceId(), currentFrontend, lastId.getFrontendId());
+                return null;
             }
 
-            LOG.debug("{}: persisting new identifier {}", persistenceId(), nextId);
-            context().saveSnapshot(nextId);
-            return new SavingClientActorBehavior(context(), nextId);
-        } else if (recover instanceof SnapshotOffer snapshotOffer) {
-            lastId = (ClientIdentifier) snapshotOffer.snapshot();
-            LOG.debug("{}: recovered identifier {}", persistenceId(), lastId);
+            nextId = ClientIdentifier.create(currentFrontend, lastId.getGeneration() + 1);
         } else {
-            LOG.warn("{}: ignoring recovery message {}", persistenceId(), recover);
+            nextId = ClientIdentifier.create(currentFrontend, initialGeneration());
         }
 
-        return this;
+        LOG.debug("{}: persisting new identifier {}", persistenceId(), nextId);
+        context().saveSnapshot(nextId);
+        return new SavingClientActorBehavior(context(), nextId);
     }
 
     private long initialGeneration() {