ebef4fe2546d6b5deda2d26ef9fc2b8bf3413478
[openflowplugin.git] / applications / inventory-manager / src / main / java / org / opendaylight / openflowplugin / applications / 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.openflowplugin.applications.inventory.manager;
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.controller.sal.binding.api.NotificationProviderService;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 public class InventoryActivator implements BindingAwareProvider, AutoCloseable {
18     private static final Logger LOG = LoggerFactory.getLogger(InventoryActivator.class);
19     private FlowCapableInventoryProvider provider;
20
21     @Override
22     public void onSessionInitiated(final ProviderContext session) {
23         DataBroker dataBroker = session.getSALService(DataBroker.class);
24         NotificationProviderService salNotifiService =
25                 session.getSALService(NotificationProviderService.class);
26
27         provider = new FlowCapableInventoryProvider(dataBroker, salNotifiService);
28         provider.start();
29     }
30
31     @Override
32     public void close() throws Exception {
33         if (provider != null) {
34             try {
35                 provider.close();
36             } catch (InterruptedException e) {
37                 LOG.warn("Interrupted while waiting for shutdown", e);
38             }
39             provider = null;
40         }
41     }
42 }