Bump versions 9.0.4-SNAPSHOT
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / RecoveringClientActorBehavior.java
index f40deab30d5bed8bbf1a7eed8da3e76653ce27bf..729d53dfc36445debce67c52174ea3729eee7ed0 100644 (file)
@@ -34,8 +34,8 @@ final class RecoveringClientActorBehavior extends AbstractClientActorBehavior<In
     private final FrontendIdentifier currentFrontend;
     private ClientIdentifier lastId = null;
 
-    RecoveringClientActorBehavior(final InitialClientActorContext context, final FrontendIdentifier frontendId) {
-        super(context);
+    RecoveringClientActorBehavior(final AbstractClientActor actor, final FrontendIdentifier frontendId) {
+        super(new InitialClientActorContext(actor, frontendId.toPersistentId()));
         currentFrontend = requireNonNull(frontendId);
     }
 
@@ -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) {
-            lastId = (ClientIdentifier) ((SnapshotOffer)recover).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() {