Merge "Bug 4957 No empty transaction for every connection fix"
[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.md.sal.common.api.clustering.EntityOwnershipService;
12 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
14 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class InventoryActivator implements BindingAwareProvider, AutoCloseable {
19     private static final Logger LOG = LoggerFactory.getLogger(InventoryActivator.class);
20     private FlowCapableInventoryProvider provider;
21     final private EntityOwnershipService eos;
22
23     public InventoryActivator(EntityOwnershipService eos) {
24         this.eos = eos;
25     }
26
27
28     @Override
29     public void onSessionInitiated(final ProviderContext session) {
30         DataBroker dataBroker = session.getSALService(DataBroker.class);
31         NotificationProviderService salNotifiService =
32                 session.getSALService(NotificationProviderService.class);
33
34         provider = new FlowCapableInventoryProvider(dataBroker, salNotifiService, eos);
35         provider.start();
36     }
37
38     @Override
39     public void close() throws Exception {
40         if (provider != null) {
41             try {
42                 provider.close();
43             } catch (InterruptedException e) {
44                 LOG.warn("Interrupted while waiting for shutdown", e);
45             }
46             provider = null;
47         }
48     }
49 }