From 9f9523addec6533bc5dad14293c8003117a13385 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 26 Aug 2019 14:57:31 +0200 Subject: [PATCH] Make notification filter a simple lambda 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 --- .../sal/connect/netconf/NetconfDevice.java | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 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 1a7ee5535f..4f8e993187 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 @@ -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 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() { @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 -- 2.36.6