Fix FindBugs warning around static invocation 87/52887/5
authorroot <rovarga@cisco.com>
Mon, 6 Mar 2017 14:32:44 +0000 (15:32 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 10 Mar 2017 16:23:13 +0000 (17:23 +0100)
For some reason FB does not like our copy-pasted code,
so centralize the formatting primitive into a dedicated
method.

Change-Id: Ia73c5d5b163181b476f0a8ac3eb4744e9d9538d3
Signed-off-by: root <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStats.java

index 765fe21..02c838a 100644 (file)
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 import javax.annotation.Nullable;
+import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.cluster.datastore.Shard;
 import org.opendaylight.controller.cluster.raft.base.messages.InitiateCaptureSnapshot;
 import org.opendaylight.controller.cluster.raft.client.messages.FollowerInfo;
@@ -38,6 +39,7 @@ import scala.concurrent.Await;
 public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
     public static final String JMX_CATEGORY_SHARD = "Shards";
 
+    @GuardedBy("DATE_FORMAT")
     private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
 
     private static final Cache<String, OnDemandRaftState> ONDEMAND_RAFT_STATE_CACHE =
@@ -107,6 +109,12 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
         return state;
     }
 
+    private static String formatMillis(final long timeMillis) {
+        synchronized (DATE_FORMAT) {
+            return DATE_FORMAT.format(new Date(timeMillis));
+        }
+    }
+
     @Override
     public String getShardName() {
         return getMBeanName();
@@ -214,9 +222,7 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
 
     @Override
     public String getLastCommittedTransactionTime() {
-        synchronized (DATE_FORMAT) {
-            return DATE_FORMAT.format(new Date(lastCommittedTransactionTime));
-        }
+        return formatMillis(lastCommittedTransactionTime);
     }
 
     @Override
@@ -299,7 +305,7 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
 
     }
 
-    public void setFollowerInitialSyncStatus(boolean followerInitialSyncStatus) {
+    public void setFollowerInitialSyncStatus(final boolean followerInitialSyncStatus) {
         this.followerInitialSyncStatus = followerInitialSyncStatus;
     }
 
@@ -342,9 +348,7 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean {
 
     @Override
     public String getLastLeadershipChangeTime() {
-        synchronized (DATE_FORMAT) {
-            return DATE_FORMAT.format(new Date(lastLeadershipChangeTime));
-        }
+        return formatMillis(lastLeadershipChangeTime);
     }
 
     @Override

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.