2 * Copyright (c) 2013 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
8 package org.opendaylight.controller.netconf.monitoring.osgi;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
12 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.framework.ServiceRegistration;
16 import org.osgi.util.tracker.ServiceTracker;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
20 import java.util.Dictionary;
21 import java.util.Hashtable;
23 public class NetconfMonitoringServiceTracker extends ServiceTracker<NetconfMonitoringService, NetconfMonitoringService> {
25 private static final Logger logger = LoggerFactory.getLogger(NetconfMonitoringServiceTracker.class);
27 private ServiceRegistration<NetconfOperationServiceFactory> reg;
29 NetconfMonitoringServiceTracker(BundleContext context) {
30 super(context, NetconfMonitoringService.class, null);
34 public NetconfMonitoringService addingService(ServiceReference<NetconfMonitoringService> reference) {
35 Preconditions.checkState(reg == null, "Monitoring service was already added");
37 NetconfMonitoringService netconfMonitoringService = super.addingService(reference);
39 final NetconfMonitoringOperationService operationService = new NetconfMonitoringOperationService(
40 netconfMonitoringService);
41 NetconfOperationServiceFactory factory = new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
44 Dictionary<String, ?> props = new Hashtable<>();
45 reg = context.registerService(NetconfOperationServiceFactory.class, factory, props);
47 return netconfMonitoringService;
51 public void removedService(ServiceReference<NetconfMonitoringService> reference,
52 NetconfMonitoringService netconfMonitoringService) {
56 } catch (Exception e) {
57 logger.warn("Ignoring exception while unregistering {}", reg, e);