From 6fb3cb49c2a1c0326906616f219eef2e386fcfc0 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 8 Dec 2022 18:00:00 +0100 Subject: [PATCH] NotificationFilter should be a predicate There is no point in passing back the notification through an optional, just return filtering true/false. Change-Id: I1275247cdfcf3c1c683b218ae4170263da54a3f5 Signed-off-by: Robert Varga --- .../netconf/sal/connect/netconf/NetconfDevice.java | 5 ++--- .../netconf/sal/connect/netconf/NotificationHandler.java | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java index c166a21fa5..bbfd411eb4 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java @@ -27,7 +27,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -221,9 +220,9 @@ public class NetconfDevice implements RemoteDevice { // Only disconnect is enough, // the reconnecting nature of the connector will take care of reconnecting listener.disconnect(); - return Optional.empty(); + return false; } - return Optional.of(notification); + return true; }); } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java index 1e65bbd216..3b03974f92 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java @@ -13,7 +13,7 @@ import static java.util.Objects.requireNonNull; import java.util.LinkedList; import java.util.List; -import java.util.Optional; +import java.util.function.Predicate; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.netconf.api.NetconfMessage; import org.opendaylight.netconf.api.xml.XmlUtil; @@ -86,7 +86,7 @@ final class NotificationHandler { private synchronized void passNotification(final DOMNotification parsedNotification) { LOG.debug("{}: Forwarding notification {}", id, parsedNotification); - if (filter == null || filter.filterNotification(parsedNotification).isPresent()) { + if (filter == null || filter.test(parsedNotification)) { salFacade.onNotification(parsedNotification); } } @@ -101,8 +101,8 @@ final class NotificationHandler { messageTransformer = null; } - interface NotificationFilter { + @FunctionalInterface + interface NotificationFilter extends Predicate { - Optional filterNotification(DOMNotification notification); } } -- 2.36.6