Mechanical code cleanup (config)
[controller.git] / opendaylight / config / config-persister-feature-adapter / src / main / java / org / opendaylight / controller / configpusherfeature / internal / ConfigPusherCustomizer.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.configpusherfeature.internal;
9
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;
18
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;
24
25     @Override
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);
32         fsst.open();
33         return cpService;
34     }
35
36     @Override
37     public void modifiedService(ServiceReference<ConfigPusher> configPusherServiceReference, ConfigPusher configPusher) {
38         // we don't care if the properties change
39     }
40
41     @Override
42     public void removedService(ServiceReference<ConfigPusher> configPusherServiceReference, ConfigPusher configPusher) {
43         this.close();
44     }
45
46     @Override
47     public void close() {
48         if(fsst != null) {
49             fsst.close();
50             fsst = null;
51         }
52         if(configFeaturesListener != null) {
53             configFeaturesListener.close();
54             configFeaturesListener = null;
55         }
56         if(featureServiceCustomizer != null) {
57             featureServiceCustomizer.close();
58             featureServiceCustomizer = null;
59         }
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.