Refactor OVSDB Neutron Code
[netvirt.git] / openstack / net-virt-providers / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / providers / MdsalConsumerImpl.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
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  * Authors : Madhu Venugopal
9  */
10
11 package org.opendaylight.ovsdb.openstack.netvirt.providers;
12
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext;
15 import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer;
16 import org.opendaylight.controller.sal.binding.api.data.DataBrokerService;
17
18 import org.apache.felix.dm.Component;
19 import org.osgi.framework.BundleContext;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 public class MdsalConsumerImpl implements BindingAwareConsumer, MdsalConsumer {
23
24     private BundleContext ctx = null;
25     private volatile BindingAwareBroker broker;
26     private ConsumerContext consumerContext = null;
27     private DataBrokerService dataBrokerService;
28
29     static final Logger logger = LoggerFactory.getLogger(MdsalConsumerImpl.class);
30
31     void init(Component c) {
32         this.ctx = c.getDependencyManager().getBundleContext();
33         logger.info("Open vSwitch OpenFlow 1.3 Neutron Networking Provider Registered with MD-SAL");
34         broker.registerConsumer(this, this.ctx);
35     }
36
37     void destroy() {
38         // Now lets close MDSAL session
39         if (this.consumerContext != null) {
40             //this.consumerContext.close();
41             this.consumerContext = null;
42         }
43     }
44
45     void start() {
46     }
47
48     void stop() {
49     }
50
51     @Override
52     public void onSessionInitialized(ConsumerContext session) {
53         this.consumerContext = session;
54         dataBrokerService = session.getSALService(DataBrokerService.class);
55         logger.info("OVSDB Neutron Session Initilized with CONSUMER CONTEXT {}", session.toString());
56     }
57
58     @Override
59     public ConsumerContext getConsumerContext() {
60         return consumerContext;
61     }
62     @Override
63     public DataBrokerService getDataBrokerService() {
64         return dataBrokerService;
65     }
66 }