Hide internals of FollowerLogInformationImpl 42/14442/3
authorRobert Varga <rovarga@cisco.com>
Fri, 23 Jan 2015 13:53:55 +0000 (14:53 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 23 Jan 2015 22:36:25 +0000 (23:36 +0100)
The constructor should not take AtomicLong instances, as that is an
implementation-specific detail. Notably the constructor assumes
ownership of the objects and no caller uses them in a shared way.

Change-Id: I587fb2033f9b513df565471f037e20e0acc481c7
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImpl.java
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/behaviors/AbstractLeader.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/FollowerLogInformationImplTest.java

index 7df80af58a717e99c1a226c3bd6cbb17ccd92afc..9820638ab706ba0753da5ff1d574bc657da9b962 100644 (file)
@@ -14,7 +14,7 @@ import scala.concurrent.duration.FiniteDuration;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
-public class FollowerLogInformationImpl implements FollowerLogInformation{
+public class FollowerLogInformationImpl implements FollowerLogInformation {
 
     private final String id;
 
@@ -26,11 +26,11 @@ public class FollowerLogInformationImpl implements FollowerLogInformation{
 
     private final long followerTimeoutMillis;
 
-    public FollowerLogInformationImpl(String id, AtomicLong nextIndex,
-        AtomicLong matchIndex, FiniteDuration followerTimeoutDuration) {
+    public FollowerLogInformationImpl(String id, long nextIndex,
+        long matchIndex, FiniteDuration followerTimeoutDuration) {
         this.id = id;
-        this.nextIndex = nextIndex;
-        this.matchIndex = matchIndex;
+        this.nextIndex = new AtomicLong(nextIndex);
+        this.matchIndex = new AtomicLong(matchIndex);
         this.stopwatch = new Stopwatch();
         this.followerTimeoutMillis = followerTimeoutDuration.toMillis();
     }
@@ -39,11 +39,13 @@ public class FollowerLogInformationImpl implements FollowerLogInformation{
         return nextIndex.incrementAndGet();
     }
 
-    @Override public long decrNextIndex() {
+    @Override
+    public long decrNextIndex() {
         return nextIndex.decrementAndGet();
     }
 
-    @Override public void setNextIndex(long nextIndex) {
+    @Override
+    public void setNextIndex(long nextIndex) {
         this.nextIndex.set(nextIndex);
     }
 
@@ -51,7 +53,8 @@ public class FollowerLogInformationImpl implements FollowerLogInformation{
         return matchIndex.incrementAndGet();
     }
 
-    @Override public void setMatchIndex(long matchIndex) {
+    @Override
+    public void setMatchIndex(long matchIndex) {
         this.matchIndex.set(matchIndex);
     }
 
index 7d45da7a64b91629cc1d9f504de47ec3fe97a94f..5606453e31be9a9303be5a28652c6e3b0b12caf9 100644 (file)
@@ -23,7 +23,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
 import org.opendaylight.controller.cluster.raft.ClientRequestTracker;
 import org.opendaylight.controller.cluster.raft.ClientRequestTrackerImpl;
 import org.opendaylight.controller.cluster.raft.FollowerLogInformation;
@@ -100,8 +99,7 @@ public abstract class AbstractLeader extends AbstractRaftActorBehavior {
         for (String followerId : followers) {
             FollowerLogInformation followerLogInformation =
                 new FollowerLogInformationImpl(followerId,
-                    new AtomicLong(context.getCommitIndex()),
-                    new AtomicLong(-1),
+                    context.getCommitIndex(), -1,
                     context.getConfigParams().getElectionTimeOutInterval());
 
             followerToLog.put(followerId, followerLogInformation);
index 7df9f3713ffc302dcf100c45a93b8fd034b0fffa..a092c46533d251414ee7f22cf843c4fc3765f691 100644 (file)
@@ -7,14 +7,12 @@
  */
 package org.opendaylight.controller.cluster.raft;
 
-
 import com.google.common.base.Stopwatch;
 import com.google.common.util.concurrent.Uninterruptibles;
 import org.junit.Test;
 import scala.concurrent.duration.FiniteDuration;
 
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -29,7 +27,7 @@ public class FollowerLogInformationImplTest {
 
         FollowerLogInformation followerLogInformation =
             new FollowerLogInformationImpl(
-                "follower1", new AtomicLong(10), new AtomicLong(9), timeoutDuration);
+                "follower1", 10, 9, timeoutDuration);