Merge "Drop the #1997-related sleep"
[ovsdb.git] / library / impl / src / main / java / org / opendaylight / ovsdb / lib / impl / LibraryProvider.java
1 /*
2  * Copyright © 2015 Red Hat, 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.ovsdb.lib.impl;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
13 import org.opendaylight.ovsdb.lib.ConfigActivator;
14 import org.opendaylight.ovsdb.lib.OvsdbConnection;
15 import org.osgi.framework.BundleContext;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 public class LibraryProvider implements BindingAwareProvider, AutoCloseable {
20
21     private static final Logger LOG = LoggerFactory.getLogger(LibraryProvider.class);
22     private final BundleContext bundleContext;
23     private DataBroker dataBroker;
24     private ConfigActivator activator;
25
26     public LibraryProvider(BundleContext bundleContext) {
27         LOG.info("LibraryProvider: bundleContext: {}", bundleContext);
28         this.bundleContext = bundleContext;
29     }
30
31     @Override
32     public void onSessionInitiated(ProviderContext providerContext) {
33         LOG.info("LibraryProvider Session Initiated");
34         dataBroker = providerContext.getSALService(DataBroker.class);
35         LOG.info("LibraryProvider: onSessionInitiated dataBroker: {}", dataBroker);
36         this.activator = new ConfigActivator(providerContext);
37         try {
38             activator.start(bundleContext);
39         } catch (Exception e) {
40             LOG.warn("Failed to start LibraryProvider: ", e);
41         }
42     }
43
44     @Override
45     public void close() throws Exception {
46         LOG.info("LibraryProvider Closed");
47         if (activator != null) {
48             activator.stop(bundleContext);
49         }
50     }
51
52 }