2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.bgpcep.bgp.topology.provider.config;
11 import static java.util.Objects.requireNonNull;
13 import com.google.common.util.concurrent.FluentFuture;
14 import org.opendaylight.bgpcep.bgp.topology.provider.AbstractTopologyBuilder;
15 import org.opendaylight.bgpcep.bgp.topology.provider.spi.BgpTopologyDeployer;
16 import org.opendaylight.bgpcep.bgp.topology.provider.spi.TopologyReferenceSingletonService;
17 import org.opendaylight.mdsal.common.api.CommitInfo;
18 import org.opendaylight.mdsal.singleton.common.api.ServiceGroupIdentifier;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
20 import org.opendaylight.yangtools.concepts.Registration;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 final class TopologyReferenceSingletonServiceImpl implements TopologyReferenceSingletonService {
26 private static final Logger LOG = LoggerFactory.getLogger(TopologyReferenceSingletonServiceImpl.class);
27 private final AbstractTopologyBuilder<?> topologyBuilder;
28 private final Registration serviceRegistration;
29 private final Topology configuration;
31 TopologyReferenceSingletonServiceImpl(final AbstractTopologyBuilder<?> topologyBuilder,
32 final BgpTopologyDeployer deployer, final Topology configuration) {
33 this.configuration = requireNonNull(configuration);
34 this.topologyBuilder = requireNonNull(topologyBuilder);
35 this.serviceRegistration = deployer.registerService(this);
39 public InstanceIdentifier<Topology> getInstanceIdentifier() {
40 return this.topologyBuilder.getInstanceIdentifier();
45 this.serviceRegistration.close();
49 public void instantiateServiceInstance() {
50 LOG.info("Topology Singleton Service {} instantiated", getIdentifier());
51 this.topologyBuilder.start();
55 public FluentFuture<? extends CommitInfo> closeServiceInstance() {
56 LOG.info("Close Topology Singleton Service {}", getIdentifier());
57 return this.topologyBuilder.close();
61 public ServiceGroupIdentifier getIdentifier() {
62 return ServiceGroupIdentifier.create(getInstanceIdentifier().firstKeyOf(Topology.class)
63 .getTopologyId().getValue());
67 public Topology getConfiguration() {
68 return this.configuration;