X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fconnect%2Fnetconf%2FNotificationHandler.java;h=481afa5c833e9e74719d4aa2593b9953b86b2083;hb=412db94945c5db5d2da918f5e23bd3abcecc4d10;hp=cc8960fb4f7233b297426dac875679d7cb509706;hpb=7feea9765c299cae1a462a5e21aee4ecd6144528;p=controller.git 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..481afa5c83 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; @@ -15,7 +16,8 @@ import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.opendaylight.controller.sal.connect.api.MessageTransformer; import org.opendaylight.controller.sal.connect.api.RemoteDeviceHandler; import org.opendaylight.controller.sal.connect.util.RemoteDeviceId; -import org.opendaylight.yangtools.yang.data.api.CompositeNode; +import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,19 +30,20 @@ final class NotificationHandler { private final RemoteDeviceHandler salFacade; private final List queue = new LinkedList<>(); - private final MessageTransformer messageTransformer; private final RemoteDeviceId id; private boolean passNotifications = false; - NotificationHandler(final RemoteDeviceHandler salFacade, final MessageTransformer messageTransformer, final RemoteDeviceId id) { + private NotificationFilter filter; + private MessageTransformer messageTransformer; + + NotificationHandler(final RemoteDeviceHandler salFacade, final RemoteDeviceId id) { this.salFacade = Preconditions.checkNotNull(salFacade); - this.messageTransformer = Preconditions.checkNotNull(messageTransformer); this.id = Preconditions.checkNotNull(id); } synchronized void handleNotification(final NetconfMessage notification) { if(passNotifications) { - passNotification(messageTransformer.toNotification(notification)); + passNotification(transformNotification(notification)); } else { queueNotification(notification); } @@ -48,17 +51,26 @@ final class NotificationHandler { /** * Forward all cached notifications and pass all notifications from this point directly to sal facade. + * @param messageTransformer */ - synchronized void onRemoteSchemaUp() { + synchronized void onRemoteSchemaUp(final MessageTransformer messageTransformer) { + this.messageTransformer = Preconditions.checkNotNull(messageTransformer); + passNotifications = true; for (final NetconfMessage cachedNotification : queue) { - passNotification(messageTransformer.toNotification(cachedNotification)); + passNotification(transformNotification(cachedNotification)); } queue.clear(); } + private ContainerNode transformNotification(final NetconfMessage cachedNotification) { + final ContainerNode parsedNotification = messageTransformer.toNotification(cachedNotification); + Preconditions.checkNotNull(parsedNotification, "%s: Unable to parse received notification: %s", id, cachedNotification); + return parsedNotification; + } + private void queueNotification(final NetconfMessage notification) { Preconditions.checkState(passNotifications == false); @@ -70,9 +82,26 @@ final class NotificationHandler { queue.add(notification); } - private void passNotification(final CompositeNode parsedNotification) { + private synchronized void passNotification(final ContainerNode 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; + } + + synchronized void onRemoteSchemaDown() { + queue.clear(); + passNotifications = false; + messageTransformer = null; + } + + static interface NotificationFilter { + + Optional> filterNotification(NormalizedNode notification); } }