7bfda36e4e599be72b471d1cafb702508c5f2003
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / NotificationPopListener.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.openflow.md.core;
9
10 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
11 import org.opendaylight.openflowplugin.openflow.md.queue.PopListener;
12 import org.opendaylight.openflowplugin.api.statistics.MessageSpy;
13 import org.opendaylight.yangtools.yang.binding.Notification;
14
15 /**
16  * general publisher to MD-SAL 
17  * 
18  * @param <T> type of supported notification
19  */
20 public class NotificationPopListener<T> implements PopListener<T> {
21     
22     private MessageSpy<? super T> messageSpy;
23     private NotificationProviderService notificationProviderService;
24     
25     /**
26      * @param messageSpy the messageSpy to set
27      */
28     public void setMessageSpy(MessageSpy<? super T> messageSpy) {
29         this.messageSpy = messageSpy;
30     }
31
32     /**
33      * @param notificationProviderService the notificationProviderService to set
34      */
35     public void setNotificationProviderService(
36             NotificationProviderService notificationProviderService) {
37         this.notificationProviderService = notificationProviderService;
38     }
39
40     @Override
41     public void onPop(T processedMessage) {
42         boolean published = false;
43         if(processedMessage instanceof Notification) {
44             if (notificationProviderService != null) {
45                 notificationProviderService.publish((Notification) processedMessage);
46                 messageSpy.spyMessage(processedMessage, MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_SUCCESS);
47                 published = true;
48             }
49         }
50         
51         if (! published) {
52             messageSpy.spyMessage(processedMessage, MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE);
53         }
54     }
55
56 }