Switch to MD-SAL APIs
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / AbstractNotificationSupplierForItemRoot.java
index ff3c0cb54b9b60287e598b5e71292ab6f09cc7a3..bd58e15e0dc585af64bfd8cdfa9644c1490ed430 100644 (file)
@@ -5,18 +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 java.util.Map.Entry;
-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.md.sal.common.api.data.AsyncDataChangeEvent;
-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;
@@ -24,29 +20,26 @@ import org.opendaylight.yangtools.yang.binding.Notification;
 
 /**
  * Class is package protected abstract implementation for all Root Items
- * Notification Suppliers
+ * Notification Suppliers.
  *
  * @param <O> - data tree item Object
  * @param <C> - Create notification
  * @param <D> - Delete notification
  */
-abstract class AbstractNotificationSupplierForItemRoot<O extends DataObject,
-                                               C extends Notification,
-                                               D extends Notification>
-                    extends AbstractNotificationSupplierBase<O>
-                    implements NotificationSupplierForItemRoot<O, C, D> {
+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
+     * Default constructor for all Root Item Notification Supplier implementation.
      *
      * @param notificationProviderService - notification publisher
-     * @param db - DataBroker for DataChangeEvent registration
-     * @param clazz - Statistics Notification Class
+     * @param db                          - DataBroker for DataTreeChangeListener registration
+     * @param clazz                       - Statistics Notification Class
      */
-    public AbstractNotificationSupplierForItemRoot(final NotificationProviderService notificationProviderService, final DataBroker db,
-            final Class<O> clazz) {
+    public AbstractNotificationSupplierForItemRoot(final NotificationPublishService notificationProviderService,
+                                                   final DataBroker db, final Class<O> clazz) {
         super(db, clazz);
         this.notificationProviderService = Preconditions.checkNotNull(notificationProviderService);
     }
@@ -80,24 +73,26 @@ abstract class AbstractNotificationSupplierForItemRoot<O extends DataObject,
     }
 
 
-    public void add(InstanceIdentifier<O> identifier , O add ){
-
-        final C notif = createNotification(add, identifier);
-        if (notif != null) {
-            notificationProviderService.publish(notif);
-        }
+    public void add(InstanceIdentifier<O> identifier, O add) {
+        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);
-        }
+    public void remove(InstanceIdentifier<O> identifier, O del) {
+        putNotification(deleteNotification(identifier.firstIdentifierOf(clazz)));
     }
 
-    public void update(InstanceIdentifier<O> identifier , O before, O after){
+    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);
+            }
+        }
+    }
 }