Implement consistency barrier in yang-store-impl.
[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.BundleEvent;
17 import org.osgi.framework.ServiceRegistration;
18 import org.osgi.util.tracker.BundleTracker;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class YangStoreActivator implements BundleActivator {
23
24     private BundleTracker bundleTracker;
25     private ServiceRegistration<YangStoreService> registration;
26     private static final Logger logger = LoggerFactory
27             .getLogger(YangStoreActivator.class);
28
29     @Override
30     public void start(BundleContext context) throws Exception {
31         ExtenderYangTrackerCustomizer customizerAndService = new ExtenderYangTrackerCustomizer();
32         bundleTracker = new BundleTracker(context, BundleEvent.RESOLVED | BundleEvent.UNRESOLVED, customizerAndService);
33         bundleTracker.open();
34
35         Dictionary<String, ?> properties = new Hashtable<>();
36         registration = context.registerService(YangStoreService.class,
37                 customizerAndService, properties);
38     }
39
40     @Override
41     public void stop(BundleContext context) throws Exception {
42         try {
43             bundleTracker.close();
44         } catch (Exception e) {
45             logger.warn("Exception while closing bundleTracker", e);
46         }
47         if (registration != null) {
48             try {
49                 registration.unregister();
50             } catch (Exception e) {
51                 logger.warn("Exception while unregistring yang store service",
52                         e);
53             }
54         }
55     }
56 }