Closed nested JSON writers
[netconf.git] / netconf / netconf-util / src / main / java / org / opendaylight / netconf / util / osgi / NetconfConfigurationActivator.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.netconf.util.osgi;
10
11 import java.util.Hashtable;
12 import org.osgi.framework.BundleActivator;
13 import org.osgi.framework.BundleContext;
14 import org.osgi.framework.Constants;
15 import org.osgi.framework.ServiceRegistration;
16 import org.osgi.service.cm.ManagedService;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class NetconfConfigurationActivator implements BundleActivator {
21     private static final Logger LOG = LoggerFactory.getLogger(NetconfConfigurationActivator.class);
22
23     // This has to match netconf config filename without .cfg suffix
24     private static final String CONFIG_PID = "netconf";
25     private static final Hashtable<String, String> PROPS = new Hashtable<>(1);
26
27     static {
28         PROPS.put(Constants.SERVICE_PID, CONFIG_PID);
29     }
30
31     private ServiceRegistration<?> configService;
32
33     @Override
34     public void start(final BundleContext bundleContext) {
35         LOG.debug("Starting netconf configuration service");
36         configService = bundleContext.registerService(ManagedService.class,
37                 new NetconfConfiguration(), PROPS);
38     }
39
40     @Override
41     public void stop(final BundleContext bundleContext) {
42         if (configService != null) {
43             LOG.debug("Unregistering netconf configuration service");
44             configService.unregister();
45             configService = null;
46         }
47     }
48 }