Fix checkstyle issues to enforce it
[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(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);
32         fsst.open();
33         return cpService;
34     }
35
36     @Override
37     public void modifiedService(final ServiceReference<ConfigPusher> configPusherServiceReference,
38                                 final ConfigPusher configPusher) {
39         // we don't care if the properties change
40     }
41
42     @Override
43     public void removedService(final ServiceReference<ConfigPusher> configPusherServiceReference,
44                                final ConfigPusher configPusher) {
45         this.close();
46     }
47
48     @Override
49     public void close() {
50         if (fsst != null) {
51             fsst.close();
52             fsst = null;
53         }
54         if (configFeaturesListener != null) {
55             configFeaturesListener.close();
56             configFeaturesListener = null;
57         }
58         if (featureServiceCustomizer != null) {
59             featureServiceCustomizer.close();
60             featureServiceCustomizer = null;
61         }
62     }
63 }

©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.