Make notification filter a simple lambda 89/83989/3
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 26 Aug 2019 12:57:31 +0000 (14:57 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 27 Aug 2019 14:56:37 +0000 (16:56 +0200)
There is no real value in having a variable for this piece of code,
make it a simple lambda.

Change-Id: I7ad83eb43dc3c1d0887bd249ec2ef9a1aaa95c58
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java

index 1a7ee5535f5f7185d889d0ed0aa0ff6672d3c393..4f8e993187eab97423d6fb1a7df834fa7facfedc 100644 (file)
@@ -32,7 +32,6 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 import org.checkerframework.checker.lock.qual.GuardedBy;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.netconf.api.NetconfMessage;
@@ -201,28 +200,19 @@ public class NetconfDevice
                 NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_PATH,
                 NetconfMessageTransformUtil.CREATE_SUBSCRIPTION_RPC_CONTENT);
 
-        final NotificationHandler.NotificationFilter filter = new NotificationHandler.NotificationFilter() {
-            @Override
-            public Optional<DOMNotification> filterNotification(final DOMNotification notification) {
-                if (isCapabilityChanged(notification)) {
-                    LOG.info("{}: Schemas change detected, reconnecting", id);
-                    // Only disconnect is enough,
-                    // the reconnecting nature of the connector will take care of reconnecting
-                    listener.disconnect();
-                    return Optional.empty();
-                }
-                return Optional.of(notification);
-            }
-
-            private boolean isCapabilityChanged(final DOMNotification notification) {
-                return notification.getBody().getNodeType().equals(NetconfCapabilityChange.QNAME);
-            }
-        };
-
         Futures.addCallback(rpcResultListenableFuture, new FutureCallback<DOMRpcResult>() {
             @Override
             public void onSuccess(final DOMRpcResult domRpcResult) {
-                notificationHandler.addNotificationFilter(filter);
+                notificationHandler.addNotificationFilter(notification -> {
+                    if (NetconfCapabilityChange.QNAME.equals(notification.getBody().getNodeType())) {
+                        LOG.info("{}: Schemas change detected, reconnecting", id);
+                        // Only disconnect is enough,
+                        // the reconnecting nature of the connector will take care of reconnecting
+                        listener.disconnect();
+                        return Optional.empty();
+                    }
+                    return Optional.of(notification);
+                });
             }
 
             @Override