SONAR TD - StatisticsContextImpl, StatisticsManagerImpl 58/45058/2
authorTomas Slusny <tomas.slusny@pantheon.sk>
Tue, 19 Jul 2016 12:51:28 +0000 (14:51 +0200)
committerAndrej Leitner <andrej.leitner@pantheon.tech>
Mon, 19 Sep 2016 08:25:40 +0000 (10:25 +0200)
- Reduced cyclomatic complexity of
  StatisticsContextImpl.chooseStat
- Reduced cyclomatic complexity of
  StatisticsManagerImpl.pollStatistics
- Fixed naming of instance fields to match
  '^[a-z][a-zA-Z0-9]*$' expression

Change-Id: Ieb9d06cda534b01240ba2a952c927667ece5565b
Signed-off-by: Tomas Slusny <tomas.slusny@pantheon.sk>
(cherry picked from commit 5c853ea0a399706a0a475638f9c542945a993bd9)

openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java

index 560481ad862db9922cd759c16f8b63e8db0bfebe..13c8e995949e27f561cb979eda3f1a030f2f1ff0 100644 (file)
@@ -59,9 +59,9 @@ class StatisticsContextImpl implements StatisticsContext {
     private final DeviceState devState;
     private final ListenableFuture<Boolean> emptyFuture;
     private final boolean shuttingDownStatisticsPolling;
-    private final Object COLLECTION_STAT_TYPE_LOCK = new Object();
     private final SinglePurposeMultipartReplyTranslator multipartReplyTranslator;
-    @GuardedBy("COLLECTION_STAT_TYPE_LOCK")
+    private final Object collectionStatTypeLock = new Object();
+    @GuardedBy("collectionStatTypeLock")
     private List<MultipartType> collectingStatType;
 
     private StatisticsGatheringService statisticsGatheringService;
@@ -98,7 +98,7 @@ class StatisticsContextImpl implements StatisticsContext {
 
     @Override
     public void statListForCollectingInitialization() {
-        synchronized (COLLECTION_STAT_TYPE_LOCK) {
+        synchronized (collectionStatTypeLock) {
             final List<MultipartType> statListForCollecting = new ArrayList<>();
             if (devState.isTableStatisticsAvailable()) {
                 statListForCollecting.add(MultipartType.OFPMPTABLE);
@@ -144,7 +144,7 @@ class StatisticsContextImpl implements StatisticsContext {
         if (errorResultFuture != null) {
             return errorResultFuture;
         }
-        synchronized (COLLECTION_STAT_TYPE_LOCK) {
+        synchronized (collectionStatTypeLock) {
             final Iterator<MultipartType> statIterator = collectingStatType.iterator();
             final SettableFuture<Boolean> settableStatResultFuture = SettableFuture.create();
 
@@ -171,27 +171,38 @@ class StatisticsContextImpl implements StatisticsContext {
     }
 
     private ListenableFuture<Boolean> chooseStat(final MultipartType multipartType, final boolean initial){
+        ListenableFuture<Boolean> result = Futures.immediateCheckedFuture(Boolean.TRUE);
+
         switch (multipartType) {
             case OFPMPFLOW:
-                return collectFlowStatistics(multipartType, initial);
+                result = collectFlowStatistics(multipartType, initial);
+                break;
             case OFPMPTABLE:
-                return collectTableStatistics(multipartType);
+                result = collectTableStatistics(multipartType);
+                break;
             case OFPMPPORTSTATS:
-                return collectPortStatistics(multipartType);
+                result = collectPortStatistics(multipartType);
+                break;
             case OFPMPQUEUE:
-                return collectQueueStatistics(multipartType);
+                result = collectQueueStatistics(multipartType);
+                break;
             case OFPMPGROUPDESC:
-                return collectGroupDescStatistics(multipartType);
+                result = collectGroupDescStatistics(multipartType);
+                break;
             case OFPMPGROUP:
-                return collectGroupStatistics(multipartType);
+                result = collectGroupStatistics(multipartType);
+                break;
             case OFPMPMETERCONFIG:
-                return collectMeterConfigStatistics(multipartType);
+                result = collectMeterConfigStatistics(multipartType);
+                break;
             case OFPMPMETER:
-                return collectMeterStatistics(multipartType);
+                result = collectMeterStatistics(multipartType);
+                break;
             default:
-                LOG.warn("Unsuported Statistics type {}", multipartType);
-                return Futures.immediateCheckedFuture(Boolean.TRUE);
+                LOG.warn("Unsupported Statistics type {}", multipartType);
         }
+
+        return result;
     }
 
 
index 01cb6d0b14a94a98fcc0531b2712ef4cb21cbd4b..7ed60e5823d2399230256049a14690b5936be7b8 100644 (file)
@@ -148,15 +148,15 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
         });
 
         final long averageTime = TimeUnit.MILLISECONDS.toSeconds(timeCounter.getAverageTimeBetweenMarks());
-        final long STATS_TIMEOUT_SEC = averageTime > 0 ? 3 * averageTime : DEFAULT_STATS_TIMEOUT_SEC;
+        final long statsTimeoutSec = averageTime > 0 ? 3 * averageTime : DEFAULT_STATS_TIMEOUT_SEC;
         final TimerTask timerTask = timeout -> {
             if (!deviceStatisticsCollectionFuture.isDone()) {
-                LOG.info("Statistics collection for node {} still in progress even after {} secs", deviceInfo.getLOGValue(), STATS_TIMEOUT_SEC);
+                LOG.info("Statistics collection for node {} still in progress even after {} secs", deviceInfo.getLOGValue(), statsTimeoutSec);
                 deviceStatisticsCollectionFuture.cancel(true);
             }
         };
 
-        hashedWheelTimer.newTimeout(timerTask, STATS_TIMEOUT_SEC, TimeUnit.SECONDS);
+        hashedWheelTimer.newTimeout(timerTask, statsTimeoutSec, TimeUnit.SECONDS);
     }
 
     private void scheduleNextPolling(final DeviceState deviceState,