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.FeaturesListener;
11 import org.apache.karaf.features.FeaturesService;
12 import org.opendaylight.controller.config.persist.api.ConfigPusher;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.ServiceReference;
15 import org.osgi.framework.ServiceRegistration;
16 import org.osgi.util.tracker.ServiceTrackerCustomizer;
18 public class FeatureServiceCustomizer implements ServiceTrackerCustomizer<FeaturesService, FeaturesService>, AutoCloseable {
19 private ConfigPusher configPusher = null;
20 private ConfigFeaturesListener configFeaturesListener = null;
21 private ServiceRegistration<?> registration;
23 FeatureServiceCustomizer(ConfigPusher c) {
29 public FeaturesService addingService(ServiceReference<FeaturesService> reference) {
30 BundleContext bc = reference.getBundle().getBundleContext();
31 FeaturesService featureService = bc.getService(reference);
32 configFeaturesListener = new ConfigFeaturesListener(configPusher,featureService);
33 registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
34 return featureService;
38 public void modifiedService(ServiceReference<FeaturesService> reference,
39 FeaturesService service) {
40 // we don't care if the properties change
45 public void removedService(ServiceReference<FeaturesService> reference,
46 FeaturesService service) {
52 if(registration != null) {
53 registration.unregister();