Fixed discard-changes for mdsal netconf, mapping code cleanup.
[controller.git] / opendaylight / md-sal / inventory-manager / src / main / java / org / opendaylight / controller / md / inventory / manager / InventoryActivator.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.md.inventory.manager;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.sal.binding.api.AbstractBindingAwareProvider;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.osgi.framework.BundleContext;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class InventoryActivator extends AbstractBindingAwareProvider {
19     private static final Logger LOG = LoggerFactory.getLogger(InventoryActivator.class);
20     private FlowCapableInventoryProvider provider;
21
22     @Override
23     public void onSessionInitiated(final ProviderContext session) {
24         DataBroker dataBroker = session.getSALService(DataBroker.class);
25         NotificationProviderService salNotifiService =
26                 session.getSALService(NotificationProviderService.class);
27
28         provider = new FlowCapableInventoryProvider(dataBroker, salNotifiService);
29         provider.start();
30     }
31
32     @Override
33     protected void stopImpl(final BundleContext context) {
34         if (provider != null) {
35             try {
36                 provider.close();
37             } catch (InterruptedException e) {
38                 LOG.warn("Interrupted while waiting for shutdown", e);
39             }
40             provider = null;
41         }
42     }
43 }