From: Tomas Slusny Date: Tue, 19 Jul 2016 12:51:28 +0000 (+0200) Subject: SONAR TD - StatisticsContextImpl, StatisticsManagerImpl X-Git-Tag: release/boron-sr1~33^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=74500b868f8cdce042c53d7bdd994a9c7ff7314c;p=openflowplugin.git SONAR TD - StatisticsContextImpl, StatisticsManagerImpl - 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 (cherry picked from commit 5c853ea0a399706a0a475638f9c542945a993bd9) --- diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java index 560481ad86..13c8e99594 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsContextImpl.java @@ -59,9 +59,9 @@ class StatisticsContextImpl implements StatisticsContext { private final DeviceState devState; private final ListenableFuture 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 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 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 statIterator = collectingStatType.iterator(); final SettableFuture settableStatResultFuture = SettableFuture.create(); @@ -171,27 +171,38 @@ class StatisticsContextImpl implements StatisticsContext { } private ListenableFuture chooseStat(final MultipartType multipartType, final boolean initial){ + ListenableFuture 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; } diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java index 01cb6d0b14..7ed60e5823 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsManagerImpl.java @@ -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,