X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNotificationHandler.java;h=80451a1027713174d66a90ead14bd184ee4a3721;hp=cc8960fb4f7233b297426dac875679d7cb509706;hb=ecabb3cf9b22efd564ef71cb60918318af19d753;hpb=54916d10764a5234881040e9a68ae35d63b3dac9 diff --git a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java index cc8960fb4f..80451a1027 100644 --- a/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java +++ b/opendaylight/md-sal/sal-netconf-connector/src/main/java/org/opendaylight/controller/sal/connect/netconf/NotificationHandler.java @@ -7,6 +7,7 @@ */ package org.opendaylight.controller.sal.connect.netconf; +import com.google.common.base.Optional; import com.google.common.base.Preconditions; import java.util.LinkedList; import java.util.List; @@ -31,6 +32,7 @@ final class NotificationHandler { private final MessageTransformer messageTransformer; private final RemoteDeviceId id; private boolean passNotifications = false; + private NotificationFilter filter; NotificationHandler(final RemoteDeviceHandler salFacade, final MessageTransformer messageTransformer, final RemoteDeviceId id) { this.salFacade = Preconditions.checkNotNull(salFacade); @@ -53,7 +55,10 @@ final class NotificationHandler { passNotifications = true; for (final NetconfMessage cachedNotification : queue) { - passNotification(messageTransformer.toNotification(cachedNotification)); + final CompositeNode parsedNotification = messageTransformer.toNotification(cachedNotification); + // TODO possible race condition here, because this exception is thrown occasionally + Preconditions.checkNotNull(parsedNotification, "Unable to parse received notification %s", cachedNotification); + passNotification(parsedNotification); } queue.clear(); @@ -70,9 +75,20 @@ final class NotificationHandler { queue.add(notification); } - private void passNotification(final CompositeNode parsedNotification) { + private synchronized void passNotification(final CompositeNode parsedNotification) { logger.debug("{}: Forwarding notification {}", id, parsedNotification); - Preconditions.checkNotNull(parsedNotification); - salFacade.onNotification(parsedNotification); + + if(filter == null || filter.filterNotification(parsedNotification).isPresent()) { + salFacade.onNotification(parsedNotification); + } + } + + synchronized void addNotificationFilter(final NotificationFilter filter) { + this.filter = filter; + } + + static interface NotificationFilter { + + Optional filterNotification(CompositeNode notification); } }