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 java.util.Dictionary;
12 import java.util.Hashtable;
13 import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService;
14 import org.opendaylight.controller.netconf.api.util.NetconfConstants;
15 import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.ServiceReference;
18 import org.osgi.framework.ServiceRegistration;
19 import org.osgi.util.tracker.ServiceTracker;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class NetconfMonitoringServiceTracker extends ServiceTracker<NetconfMonitoringService, NetconfMonitoringService> {
25 private static final Logger LOG = LoggerFactory.getLogger(NetconfMonitoringServiceTracker.class);
27 private ServiceRegistration<NetconfOperationServiceFactory> reg;
29 NetconfMonitoringServiceTracker(final BundleContext context) {
30 super(context, NetconfMonitoringService.class, null);
34 public NetconfMonitoringService addingService(final ServiceReference<NetconfMonitoringService> reference) {
35 Preconditions.checkState(reg == null, "Monitoring service was already added");
37 final NetconfMonitoringService netconfMonitoringService = super.addingService(reference);
39 final NetconfMonitoringOperationService operationService = new NetconfMonitoringOperationService(
40 netconfMonitoringService);
41 final NetconfOperationServiceFactory factory = new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(
44 Dictionary<String, String> properties = new Hashtable<>();
45 properties.put(NetconfConstants.SERVICE_NAME, NetconfConstants.NETCONF_MONITORING);
46 reg = context.registerService(NetconfOperationServiceFactory.class, factory, properties);
48 return netconfMonitoringService;
52 public void removedService(final ServiceReference<NetconfMonitoringService> reference,
53 final NetconfMonitoringService netconfMonitoringService) {
57 } catch (final Exception e) {
58 LOG.warn("Ignoring exception while unregistering {}", reg, e);