2 * Copyright (c) 2014 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.configpusherfeature.internal;
10 import org.apache.karaf.features.FeaturesService;
11 import org.opendaylight.controller.config.persist.api.ConfigPusher;
12 import org.osgi.framework.BundleContext;
13 import org.osgi.framework.ServiceReference;
14 import org.osgi.util.tracker.ServiceTracker;
15 import org.osgi.util.tracker.ServiceTrackerCustomizer;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public class ConfigPusherCustomizer implements ServiceTrackerCustomizer<ConfigPusher, ConfigPusher>, AutoCloseable {
20 private static final Logger LOG = LoggerFactory.getLogger(ConfigPusherCustomizer.class);
21 private ConfigFeaturesListener configFeaturesListener = null;
22 private FeatureServiceCustomizer featureServiceCustomizer = null;
23 private ServiceTracker<FeaturesService,FeaturesService> fsst = null;
26 public ConfigPusher addingService(ServiceReference<ConfigPusher> configPusherServiceReference) {
27 LOG.trace("Got ConfigPusherCustomizer.addingService {}", configPusherServiceReference);
28 BundleContext bc = configPusherServiceReference.getBundle().getBundleContext();
29 ConfigPusher cpService = bc.getService(configPusherServiceReference);
30 featureServiceCustomizer = new FeatureServiceCustomizer(cpService);
31 fsst = new ServiceTracker<>(bc, FeaturesService.class.getName(), featureServiceCustomizer);
37 public void modifiedService(ServiceReference<ConfigPusher> configPusherServiceReference, ConfigPusher configPusher) {
38 // we don't care if the properties change
42 public void removedService(ServiceReference<ConfigPusher> configPusherServiceReference, ConfigPusher configPusher) {
52 if(configFeaturesListener != null) {
53 configFeaturesListener.close();
54 configFeaturesListener = null;
56 if(featureServiceCustomizer != null) {
57 featureServiceCustomizer.close();
58 featureServiceCustomizer = null;