Revert "Bug-2827: role switch proposal"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / NotificationPopListener.java
index 67dc838564766681323c0752dfbc8a563f187cdb..28f2a72d156c4f65ca0a2c6b1b608cc0b9e10ee2 100644 (file)
@@ -1,23 +1,56 @@
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.openflow.md.core;
 
-import java.util.List;
-
-import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
-import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.openflowplugin.api.openflow.md.queue.PopListener;
+import org.opendaylight.openflowplugin.api.statistics.MessageSpy;
 import org.opendaylight.yangtools.yang.binding.Notification;
 
+/**
+ * general publisher to MD-SAL 
+ * 
+ * @param <T> type of supported notification
+ */
 public class NotificationPopListener<T> implements PopListener<T> {
+    
+    private MessageSpy<? super T> messageSpy;
+    private NotificationProviderService notificationProviderService;
+    
+    /**
+     * @param messageSpy the messageSpy to set
+     */
+    public void setMessageSpy(MessageSpy<? super T> messageSpy) {
+        this.messageSpy = messageSpy;
+    }
 
+    /**
+     * @param notificationProviderService the notificationProviderService to set
+     */
+    public void setNotificationProviderService(
+            NotificationProviderService notificationProviderService) {
+        this.notificationProviderService = notificationProviderService;
+    }
 
     @Override
-    public void onPop(List<T> processedMessage) {
-        OFSessionUtil.getSessionManager().getTranslatorMapping();
-        for ( T message : processedMessage ) {
-            if(message instanceof Notification) {
-                OFSessionUtil.getSessionManager().getNotificationProviderService().publish((Notification) message);
+    public void onPop(T processedMessage) {
+        boolean published = false;
+        if(processedMessage instanceof Notification) {
+            if (notificationProviderService != null) {
+                notificationProviderService.publish((Notification) processedMessage);
+                messageSpy.spyMessage(processedMessage, MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
+                published = true;
             }
         }
-
+        
+        if (! published) {
+            messageSpy.spyMessage(processedMessage, MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE);
+        }
     }
 
 }