2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.bgpcep.pcep.topology.provider.config;
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.net.InetSocketAddress;
13 import java.util.HashMap;
15 import javax.annotation.concurrent.GuardedBy;
16 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
17 import org.opendaylight.controller.config.yang.pcep.topology.provider.PCEPTopologyProviderRuntimeRegistrator;
18 import org.opendaylight.protocol.concepts.KeyMapping;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
20 import org.osgi.service.blueprint.container.BlueprintContainer;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public class PCEPTopologyDeployerImpl implements PCEPTopologyDeployer, AutoCloseable {
25 private static final Logger LOG = LoggerFactory.getLogger(PCEPTopologyDeployerImpl.class);
28 private final Map<TopologyId, PCEPTopologyProviderBean> pcepTopologyServices = new HashMap<>();
29 private final BlueprintContainer container;
31 public PCEPTopologyDeployerImpl(final BlueprintContainer container) {
32 this.container = Preconditions.checkNotNull(container);
36 public synchronized void createTopologyProvider(final TopologyId topologyId,
37 final InetSocketAddress inetSocketAddress, final short rpcTimeout, final Optional<KeyMapping> keys,
38 final InstructionScheduler schedulerDependency,
39 final Optional<PCEPTopologyProviderRuntimeRegistrator> runtime) {
40 if (this.pcepTopologyServices.containsKey(topologyId)) {
41 LOG.warn("Topology Provider {} already exist. New instance won't be created", topologyId);
44 final PCEPTopologyProviderBean PCEPTopologyProviderBean = (PCEPTopologyProviderBean) this.container
45 .getComponentInstance(PCEPTopologyProviderBean.class.getSimpleName());
46 this.pcepTopologyServices.put(topologyId, PCEPTopologyProviderBean);
47 final PCEPTopologyConfigDependencies configDependencies = new PCEPTopologyConfigDependencies(inetSocketAddress,
48 keys, schedulerDependency, topologyId, runtime, rpcTimeout);
49 PCEPTopologyProviderBean.start(configDependencies);
53 public synchronized void removeTopologyProvider(final TopologyId topologyID) {
54 final PCEPTopologyProviderBean service = this.pcepTopologyServices.remove(topologyID);
55 if (service != null) {
61 public synchronized void close() throws Exception {
62 this.pcepTopologyServices.values().forEach(PCEPTopologyProviderBean::close);