BUG-5626: do not use needless cast 09/36909/2
authorRobert Varga <rovarga@cisco.com>
Wed, 30 Mar 2016 17:54:45 +0000 (19:54 +0200)
committerRobert Varga <rovarga@cisco.com>
Thu, 31 Mar 2016 08:22:44 +0000 (10:22 +0200)
Casting to Follower is not needed, as we can access the leader ID from
the RaftActorBehavior interface.

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

index 620b2eb422bfb5576c7f8dc73fd74e631c45aa74..374b2a7e78835ef4531660ac0aa638fd89151e7b 100644 (file)
@@ -610,8 +610,8 @@ public abstract class RaftActor extends AbstractUntypedPersistentActor {
             // but transfer the previous leaderId so it doesn't immediately try to schedule an election. This
             // avoids potential disruption. Otherwise, switch to Follower normally.
             RaftActorBehavior behavior = getCurrentBehavior();
             // but transfer the previous leaderId so it doesn't immediately try to schedule an election. This
             // avoids potential disruption. Otherwise, switch to Follower normally.
             RaftActorBehavior behavior = getCurrentBehavior();
-            if(behavior instanceof Follower) {
-                String previousLeaderId = ((Follower)behavior).getLeaderId();
+            if (behavior != null && behavior.state() == RaftState.Follower) {
+                String previousLeaderId = behavior.getLeaderId();
                 short previousLeaderPayloadVersion = behavior.getLeaderPayloadVersion();
 
                 LOG.debug("{}: Re-initializing to Follower with previous leaderId {}", persistenceId(), previousLeaderId);
                 short previousLeaderPayloadVersion = behavior.getLeaderPayloadVersion();
 
                 LOG.debug("{}: Re-initializing to Follower with previous leaderId {}", persistenceId(), previousLeaderId);
index 237e5eeaae1e001388fad692520c1b64d0a43125..43704d8cfed1ccc2c95266164258c6ad7999f7a1 100644 (file)
@@ -428,7 +428,8 @@ public abstract class AbstractRaftActorBehavior implements RaftActorBehavior {
         return this;
     }
 
         return this;
     }
 
-    @Override public String getLeaderId() {
+    @Override
+    public String getLeaderId() {
         return leaderId;
     }
 
         return leaderId;
     }