Initial code drop of yang model driven configuration system
[controller.git] / opendaylight / config / yang-store-impl / src / main / java / org / opendaylight / controller / config / yang / store / impl / YangStoreActivator.java
1 /*
2  * Copyright (c) 2013 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.config.yang.store.impl;
9
10 import java.util.Dictionary;
11 import java.util.Hashtable;
12
13 import org.opendaylight.controller.config.yang.store.api.YangStoreService;
14 import org.osgi.framework.BundleActivator;
15 import org.osgi.framework.BundleContext;
16 import org.osgi.framework.ServiceRegistration;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class YangStoreActivator implements BundleActivator {
21
22     private ExtenderYangTracker extender;
23     private ServiceRegistration<YangStoreService> registration;
24     private static final Logger logger = LoggerFactory
25             .getLogger(YangStoreActivator.class);
26
27     @Override
28     public void start(BundleContext context) throws Exception {
29         extender = new ExtenderYangTracker(context);
30         extender.open();
31
32         Dictionary<String, ?> properties = new Hashtable<>();
33         registration = context.registerService(YangStoreService.class,
34                 extender, properties);
35     }
36
37     @Override
38     public void stop(BundleContext context) throws Exception {
39         try {
40             extender.close();
41         } catch (Exception e) {
42             logger.warn("Exception while closing extender", e);
43         }
44
45         if (registration != null)
46             try {
47                 registration.unregister();
48             } catch (Exception e) {
49                 logger.warn("Exception while unregistring yang store service",
50                         e);
51             }
52     }
53 }