NotificationFilter should be a predicate 30/103630/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Dec 2022 17:00:00 +0000 (18:00 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 8 Dec 2022 17:00:39 +0000 (18:00 +0100)
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 <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NotificationHandler.java

index c166a21fa518dcfcd67d177c8a02896900d3de87..bbfd411eb4f1e103ec37f6cd9f03e481728e0adc 100644 (file)
@@ -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<NetconfDeviceCommunicator> {
                         // 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;
                 });
             }
 
index 1e65bbd216687e409d5ddff746105682dd8abf30..3b03974f92f49f932ce6971ae612e7a8487b9585 100644 (file)
@@ -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<DOMNotification> {
 
-        Optional<DOMNotification> filterNotification(DOMNotification notification);
     }
 }