Merge "Untangle the XML/Hello message decoders"
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / InventoryNotificationProvider.java
1 package org.opendaylight.controller.sal.compatibility;
2
3 import java.util.List;
4
5 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
6 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
7 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
11 import org.opendaylight.yangtools.concepts.ListenerRegistration;
12 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 public class InventoryNotificationProvider implements AutoCloseable{
17
18     private ListenerRegistration<DataChangeListener> nodeConnectorDataChangeListenerRegistration;
19
20     private NodeConnectorDataChangeListener nodeConnectorDataChangeListener;
21
22     private DataProviderService dataProviderService;
23
24     private List<IPluginOutInventoryService> inventoryPublisher;
25
26     private final static Logger LOG = LoggerFactory.getLogger(NodeConnectorDataChangeListener.class);
27
28     public void start(){
29
30         LOG.info("InventoryNotificationProvider started");
31
32         if(dataProviderService != null
33                 && inventoryPublisher!= null){
34
35             if(nodeConnectorDataChangeListener == null){
36                 InstanceIdentifier<NodeConnector> nodeConnectorPath = InstanceIdentifier.builder(Nodes.class).child(Node.class).child(NodeConnector.class).build();
37                 nodeConnectorDataChangeListener = new NodeConnectorDataChangeListener();
38                 nodeConnectorDataChangeListener.setInventoryPublisher(inventoryPublisher);
39                 nodeConnectorDataChangeListenerRegistration = dataProviderService.registerDataChangeListener(nodeConnectorPath, nodeConnectorDataChangeListener);
40             }
41
42         }
43     }
44
45     @Override
46     public void close() throws Exception {
47         if(nodeConnectorDataChangeListenerRegistration != null){
48             nodeConnectorDataChangeListenerRegistration.close();
49         }
50     }
51
52     public void setDataProviderService(DataProviderService dataProviderService) {
53         this.dataProviderService = dataProviderService;
54     }
55
56     public void setInventoryPublisher(List<IPluginOutInventoryService> inventoryPublisher) {
57         this.inventoryPublisher = inventoryPublisher;
58     }
59 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.