Merge "BUG 2676 : Use transaction-dispatcher for ShardTransaction"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / NotificationHandler.java
index b5927f0bd540519ca60aadd4b095df3e81acbc89..bc3326e1ae5b58dc23dc7c14927a83d5d34d1fcf 100644 (file)
@@ -42,7 +42,7 @@ final class NotificationHandler {
 
     synchronized void handleNotification(final NetconfMessage notification) {
         if(passNotifications) {
-            passNotification(messageTransformer.toNotification(notification));
+            passNotification(transformNotification(notification));
         } else {
             queueNotification(notification);
         }
@@ -55,12 +55,18 @@ final class NotificationHandler {
         passNotifications = true;
 
         for (final NetconfMessage cachedNotification : queue) {
-            passNotification(messageTransformer.toNotification(cachedNotification));
+            passNotification(transformNotification(cachedNotification));
         }
 
         queue.clear();
     }
 
+    private CompositeNode transformNotification(final NetconfMessage cachedNotification) {
+        final CompositeNode 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);
 
@@ -74,7 +80,6 @@ final class NotificationHandler {
 
     private synchronized void passNotification(final CompositeNode parsedNotification) {
         logger.debug("{}: Forwarding notification {}", id, parsedNotification);
-        Preconditions.checkNotNull(parsedNotification);
 
         if(filter == null || filter.filterNotification(parsedNotification).isPresent()) {
             salFacade.onNotification(parsedNotification);
@@ -85,6 +90,11 @@ final class NotificationHandler {
         this.filter = filter;
     }
 
+    synchronized void onRemoteSchemaDown() {
+        queue.clear();
+        passNotifications = false;
+    }
+
     static interface NotificationFilter {
 
         Optional<CompositeNode> filterNotification(CompositeNode notification);