4e3cf69817a3f68eeeb5cf9f5bbaac4ef59512bc
[controller.git] / opendaylight / md-sal / compatibility / sal-compatibility / src / main / java / org / opendaylight / controller / sal / compatibility / topology / TopologyAdapter.java
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.md.sal.binding.util.TypeSafeDataReader;
11 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
12 import org.opendaylight.controller.sal.topology.IPluginInTopologyService;
13 import org.opendaylight.controller.sal.topology.IPluginOutTopologyService;
14 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19
20 import com.google.common.base.Preconditions;
21
22 public class TopologyAdapter implements IPluginInTopologyService {
23     private final InstanceIdentifier<Topology> topology = InstanceIdentifier.builder(NetworkTopology.class)
24             .child(Topology.class, new TopologyKey(new TopologyId("flow:1"))).toInstance();
25
26     // Injected via Apache DM
27     private IPluginOutTopologyService topologyPublisher;
28
29
30     private DataProviderService dataService;
31
32     public void setDataService(final DataProviderService dataService) {
33         this.dataService = Preconditions.checkNotNull(dataService);
34     }
35
36     @Override
37     public void sollicitRefresh() {
38         final TypeSafeDataReader reader = TypeSafeDataReader.forReader(dataService);
39         final Topology t = reader.readOperationalData(topology);
40         topologyPublisher.edgeUpdate(TopologyMapping.toADEdgeUpdates(t, reader));
41     }
42
43     public IPluginOutTopologyService getTopologyPublisher() {
44         return topologyPublisher;
45     }
46
47     public void setTopologyPublisher(final IPluginOutTopologyService topologyPublisher) {
48         this.topologyPublisher = topologyPublisher;
49     }
50 }