Handle snapshot support messages first 97/36297/2
authorRobert Varga <rovarga@cisco.com>
Wed, 16 Mar 2016 13:50:56 +0000 (14:50 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 21 Mar 2016 11:11:43 +0000 (11:11 +0000)
This checks with snapshot snapshot support first, making the code a bit
more readable.

Change-Id: I1a9ea097d71b2f28771e19b2b1979ebff0f15e7a
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/RaftActor.java

index 90b16b8..e0858b0 100644 (file)
@@ -208,9 +208,14 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
 
     @Override
     protected void handleCommand(final Object message) {
-        if(serverConfigurationSupport.handleMessage(message, getSender())) {
+        if (serverConfigurationSupport.handleMessage(message, getSender())) {
             return;
-        } else if (message instanceof ApplyState){
+        }
+        if (snapshotSupport.handleSnapshotMessage(message, getSender())) {
+            return;
+        }
+
+        if (message instanceof ApplyState) {
             ApplyState applyState = (ApplyState) message;
 
             long elapsedTime = (System.nanoTime() - applyState.getStartTime());
@@ -238,7 +243,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
                 context.getSnapshotManager().trimLog(context.getLastApplied(), currentBehavior);
             }
 
-        } else if (message instanceof ApplyJournalEntries){
+        } else if (message instanceof ApplyJournalEntries) {
             ApplyJournalEntries applyEntries = (ApplyJournalEntries) message;
             if(LOG.isDebugEnabled()) {
                 LOG.debug("{}: Persisting ApplyLogEntries with index={}", persistenceId(), applyEntries.getToIndex());
@@ -255,7 +260,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             onGetOnDemandRaftStats();
         } else if(message instanceof InitiateCaptureSnapshot) {
             captureSnapshot();
-        } else if(message instanceof SwitchBehavior){
+        } else if(message instanceof SwitchBehavior) {
             switchBehavior(((SwitchBehavior) message));
         } else if(message instanceof LeaderTransitioning) {
             onLeaderTransitioning();
@@ -263,7 +268,7 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             onShutDown();
         } else if(message instanceof Runnable) {
             ((Runnable)message).run();
-        } else if(!snapshotSupport.handleSnapshotMessage(message, getSender())) {
+        } else {
             switchBehavior(reusableSwitchBehaviorSupplier.handleMessage(getSender(), message));
         }
     }