BUG-432 Registration change
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTestNodeConnectorNotification.java
1 /**
2  * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. 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  * Contributor: gaurav.bhagwani@ericsson.com
9  */
10 package org.opendaylight.openflowplugin.test;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
16 import org.opendaylight.controller.sal.binding.api.NotificationService;
17 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.OpendaylightInventoryListener;
23 import org.opendaylight.yangtools.concepts.Registration;
24 import org.osgi.framework.BundleContext;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class OpenflowpluginTestNodeConnectorNotification {
29
30     private static final Logger LOG = LoggerFactory.getLogger(OpenflowpluginTestCommandProvider.class);
31
32     private DataBrokerService dataBrokerService;
33     private ProviderContext pc;
34     private final BundleContext ctx;
35     private final PortEventListener portEventListener = new PortEventListener();
36     private static NotificationService notificationService;
37     private Registration listenerReg;
38
39     public OpenflowpluginTestNodeConnectorNotification(BundleContext ctx) {
40         this.ctx = ctx;
41     }
42
43     public void onSessionInitiated(ProviderContext session) {
44         pc = session;
45         notificationService = session.getSALService(NotificationService.class);
46         // For switch events
47         listenerReg = notificationService.registerNotificationListener(portEventListener);
48         dataBrokerService = session.getSALService(DataBrokerService.class);
49     }
50
51     final class PortEventListener implements OpendaylightInventoryListener {
52
53         List<NodeUpdated> nodeUpdated = new ArrayList<>();
54         List<NodeRemoved> nodeRemoved = new ArrayList<>();
55         List<NodeConnectorUpdated> nodeConnectorUpdated = new ArrayList<>();
56         List<NodeConnectorRemoved> nodeConnectorRemoved = new ArrayList<>();
57
58         @Override
59         public void onNodeConnectorRemoved(NodeConnectorRemoved notification) {
60             LOG.debug("NodeConnectorRemoved Notification ...................");
61             LOG.debug("NodeConnectorRef " + notification.getNodeConnectorRef());
62             LOG.debug("----------------------------------------------------------------------");
63             nodeConnectorRemoved.add(notification);
64         }
65
66         @Override
67         public void onNodeConnectorUpdated(NodeConnectorUpdated notification) {
68             LOG.debug("NodeConnectorUpdated Notification...................");
69             LOG.debug("NodeConnectorRef " + notification.getNodeConnectorRef());
70             LOG.debug("----------------------------------------------------------------------");
71             nodeConnectorUpdated.add(notification);
72         }
73
74         @Override
75         public void onNodeRemoved(NodeRemoved notification) {
76             LOG.debug("NodeRemoved Notification ...................");
77             LOG.debug("NodeRef " + notification.getNodeRef());
78             LOG.debug("----------------------------------------------------------------------");
79             nodeRemoved.add(notification);
80         }
81
82         @Override
83         public void onNodeUpdated(NodeUpdated notification) {
84             LOG.debug("NodeUpdated Notification ...................");
85             LOG.debug("NodeRef " + notification.getNodeRef());
86             LOG.debug("----------------------------------------------------------------------");
87             nodeUpdated.add(notification);
88         }
89     }
90 }