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 620b2eb..374b2a7 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();
-            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);