From 5059c1533b433972148f4f604a7d88c4e9b26971 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 20 Jun 2019 12:20:38 +0200 Subject: [PATCH] Simplify DeviceContextImpl flow counting The code to count flows for debugging purposes is a rather arcane stream. Simplify it by transforming some amount of code from functional to imperative programming and taking advantage of nonnullFoo() methods. Change-Id: Ifa61e38b4a4e4ac786d598ba6199ed2d55304407 Signed-off-by: Robert Varga --- .../impl/device/DeviceContextImpl.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java index f8fc0f91e8..2e7ee079f7 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java @@ -15,7 +15,6 @@ import com.google.common.util.concurrent.MoreExecutors; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import io.netty.util.HashedWheelTimer; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -729,22 +728,18 @@ public class DeviceContextImpl implements DeviceContext, ExtensionConverterProvi // Count all flows we read from datastore for debugging purposes. // This number do not always represent how many flows were actually added // to DeviceFlowRegistry, because of possible duplicates. - long flowCount = Optional.ofNullable(result) - .map(Collections::singleton) - .orElse(Collections.emptySet()) - .stream() - .flatMap(Collection::stream) - .filter(Objects::nonNull) - .flatMap(flowCapableNodeOptional - -> com.google.common.base.Optional.fromJavaUtil(flowCapableNodeOptional).asSet().stream()) - .filter(Objects::nonNull) - .filter(flowCapableNode -> flowCapableNode.getTable() != null) - .flatMap(flowCapableNode -> flowCapableNode.getTable().stream()) - .filter(Objects::nonNull) - .filter(table -> table.getFlow() != null) - .flatMap(table -> table.getFlow().stream()) - .filter(Objects::nonNull) - .count(); + long flowCount = 0; + if (result != null) { + for (Optional optNode : result) { + if (optNode.isPresent()) { + flowCount += optNode.get().nonnullTable().stream() + .filter(Objects::nonNull) + .flatMap(table -> table.nonnullFlow().stream()) + .filter(Objects::nonNull) + .count(); + } + } + } LOG.debug("Finished filling flow registry with {} flows for node: {}", flowCount, deviceInfo); } -- 2.36.6