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(final 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(final ServiceReference<ConfigPusher> configPusherServiceReference,
38 final ConfigPusher configPusher) {
39 // we don't care if the properties change
43 public void removedService(final ServiceReference<ConfigPusher> configPusherServiceReference,
44 final ConfigPusher configPusher) {
54 if (configFeaturesListener != null) {
55 configFeaturesListener.close();
56 configFeaturesListener = null;
58 if (featureServiceCustomizer != null) {
59 featureServiceCustomizer.close();
60 featureServiceCustomizer = null;