Avoid nullpointer exception on starting up the TopologyProvider and the InventorReadA...
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / topology / TopologyProvider.xtend
1 /*
2  * Copyright (c) 2014 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.controller.sal.compatibility.topology
9
10 import org.opendaylight.controller.sal.binding.api.data.DataProviderService
11 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
12 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology
13 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey
16 import org.opendaylight.yangtools.yang.binding.DataObject
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
18 import org.opendaylight.yangtools.concepts.Registration
19 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler
20 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Link
21 import org.slf4j.LoggerFactory
22
23 class TopologyProvider implements AutoCloseable{
24     static val LOG = LoggerFactory.getLogger(TopologyProvider);
25     TopologyCommitHandler commitHandler
26     
27     @Property
28     IPluginOutTopologyService topologyPublisher;
29     
30     @Property
31     DataProviderService dataService;
32     
33     Registration<DataCommitHandler<InstanceIdentifier<? extends DataObject>,DataObject>> commitHandlerRegistration;
34
35     def void start() {
36
37     }
38     def void startAdapter() {
39         if(dataService == null){
40             LOG.error("dataService not set");
41             return;
42         }
43         commitHandler = new TopologyCommitHandler(dataService)
44         commitHandler.setTopologyPublisher(topologyPublisher)
45         val InstanceIdentifier<? extends DataObject> path = InstanceIdentifier.builder(NetworkTopology)
46             .child(Topology,new TopologyKey(new TopologyId("flow:1")))
47             .child(Link)
48             .toInstance();
49         commitHandlerRegistration = dataService.registerCommitHandler(path,commitHandler);
50         LOG.info("TopologyProvider started")
51     }
52     
53     override close() throws Exception {
54         commitHandlerRegistration.close
55     }
56     
57     def setTopologyPublisher(IPluginOutTopologyService topologyPublisher) {
58         _topologyPublisher = topologyPublisher;
59         if(commitHandler != null){
60             commitHandler.setTopologyPublisher(topologyPublisher);
61         }
62     }
63     
64 }