SONAR TD - StatisticsContextImpl, StatisticsManagerImpl 46/42046/4
authorTomas Slusny <tomas.slusny@pantheon.sk>
Tue, 19 Jul 2016 12:51:28 +0000 (14:51 +0200)
committerTomas Slusny <tomas.slusny@pantheon.sk>
Mon, 15 Aug 2016 12:38:11 +0000 (14:38 +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>
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 9c8755e83de2ff7f07644bc8130366d5e809a362..310f5842ad6ec268e9a7989332c0a5d221bdbfcc 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;
@@ -96,7 +96,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);
@@ -142,7 +142,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();
 
@@ -169,27 +169,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 98e6d993e42abe188772aa33c6c2445398bb4661..06e7863e3eb5e0e1f5adcffbed139b9730c0b83b 100644 (file)
@@ -126,8 +126,7 @@ public class StatisticsManagerImpl implements StatisticsManager, StatisticsManag
             @Override
             public void onFailure(@Nonnull final Throwable throwable) {
                 timeCounter.addTimeMark();
-                LOG.warn("Statistics gathering for single node was not successful: {}", throwable.getMessage());
-                LOG.trace("Statistics gathering for single node was not successful.. ", throwable);
+                LOG.warn("Statistics gathering for single node was not successful: {}", throwable);
                 calculateTimerDelay(timeCounter);
                 if (throwable instanceof CancellationException) {
                     /* This often happens when something wrong with akka or DS, so closing connection will help to restart device **/
@@ -139,15 +138,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,