Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / AbstractNotificationSupplierForItemRoot.java
index 92f05a2723f0c4a661291f335191aef1b8294f81..bd58e15e0dc585af64bfd8cdfa9644c1490ed430 100644 (file)
@@ -5,15 +5,14 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.applications.notification.supplier.impl;
 
 import com.google.common.base.Preconditions;
 import java.util.Collection;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
-import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.DataObjectModification;
+import org.opendaylight.mdsal.binding.api.DataTreeModification;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.openflowplugin.applications.notification.supplier.NotificationSupplierForItemRoot;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -30,7 +29,7 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 public abstract class AbstractNotificationSupplierForItemRoot<O extends DataObject, C extends Notification, D extends
         Notification> extends AbstractNotificationSupplierBase<O> implements NotificationSupplierForItemRoot<O, C, D> {
 
-    private final NotificationProviderService notificationProviderService;
+    private final NotificationPublishService notificationProviderService;
 
     /**
      * Default constructor for all Root Item Notification Supplier implementation.
@@ -39,7 +38,7 @@ public abstract class AbstractNotificationSupplierForItemRoot<O extends DataObje
      * @param db                          - DataBroker for DataTreeChangeListener registration
      * @param clazz                       - Statistics Notification Class
      */
-    public AbstractNotificationSupplierForItemRoot(final NotificationProviderService notificationProviderService,
+    public AbstractNotificationSupplierForItemRoot(final NotificationPublishService notificationProviderService,
                                                    final DataBroker db, final Class<O> clazz) {
         super(db, clazz);
         this.notificationProviderService = Preconditions.checkNotNull(notificationProviderService);
@@ -75,23 +74,25 @@ public abstract class AbstractNotificationSupplierForItemRoot<O extends DataObje
 
 
     public void add(InstanceIdentifier<O> identifier, O add) {
-
-        final C notif = createNotification(add, identifier);
-        if (notif != null) {
-            notificationProviderService.publish(notif);
-        }
+        putNotification(createNotification(add, identifier));
     }
 
     public void remove(InstanceIdentifier<O> identifier, O del) {
-        final D notif = deleteNotification(identifier.firstIdentifierOf(clazz));
-        if (notif != null) {
-            notificationProviderService.publish(notif);
-        }
+        putNotification(deleteNotification(identifier.firstIdentifierOf(clazz)));
     }
 
     public void update(InstanceIdentifier<O> identifier, O before, O after) {
         //EMPTY NO-OP
     }
 
+    private void putNotification(Notification notif) {
+        if (notif != null) {
+            try {
+                notificationProviderService.putNotification(notif);
+            } catch (InterruptedException e) {
+                throw new IllegalStateException("Interrupted while publishing " + notif, e);
+            }
+        }
+    }
 }