560aece98c247247002501aa575047407f86a68b
[netvirt.git] / neutron / src / main / java / org / opendaylight / ovsdb / neutron / MDSALConsumer.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.neutron;
12 import org.apache.felix.dm.Component;
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 import org.osgi.framework.BundleContext;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 public class MDSALConsumer implements BindingAwareConsumer, IMDSALConsumer {
21
22     private BundleContext ctx = null;
23     private BindingAwareBroker broker = null;
24     private ConsumerContext consumerContext = null;
25     private DataBrokerService dataBrokerService;
26
27     static final Logger logger = LoggerFactory.getLogger(MDSALConsumer.class);
28
29     void setBindingAwareBroker (BindingAwareBroker b) {
30         this.broker = b;
31     }
32
33     void unsetBindingAwareBroker(BindingAwareBroker b) {
34         if (this.broker == b) {
35             this.broker = null;
36         }
37     }
38
39     void init(Component c) {
40         this.ctx = c.getDependencyManager().getBundleContext();
41         logger.info("OVSDB Neutron Registered with MD-SAL");
42         broker.registerConsumer(this, this.ctx);
43     }
44
45     void destroy() {
46         // Now lets close MDSAL session
47         if (this.consumerContext != null) {
48             //this.consumerContext.close();
49             this.consumerContext = null;
50         }
51     }
52
53     void start() {
54     }
55
56     void stop() {
57     }
58
59     @Override
60     public void onSessionInitialized(ConsumerContext session) {
61         this.consumerContext = session;
62         dataBrokerService = session.getSALService(DataBrokerService.class);
63         logger.info("OVSDB Neutron Session Initilized with CONSUMER CONTEXT {}", session.toString());
64     }
65
66     @Override
67     public ConsumerContext getConsumerContext() {
68         return consumerContext;
69     }
70     @Override
71     public DataBrokerService getDataBrokerService() {
72         return dataBrokerService;
73     }
74 }